当前位置:网站首页>P3166 number triangle (tolerance and exclusion +gcd)
P3166 number triangle (tolerance and exclusion +gcd)
2022-07-26 01:47:00 【to cling】
Problem
Given a N × M N\times M N×M The grid of , Please calculate the total number of triangles with three points on the grid . Note that the three points of a triangle cannot be collinear .
Solution
- For two points in the grid , Let the difference between the horizontal and vertical coordinates be :i,j
Then the number of integer lattice points on the line between these two points is : g c d ( i , j ) − 1 gcd(i, j) - 1 gcd(i,j)−1
prove : At two o 'clock (0,0) and (6, 9) The difference between the horizontal and vertical coordinates of is (6, 9).
The point of (2, 3),(4, 6),(6, 9) These three points are on the line between these two points .
( According to this conclusion : If the difference between the coordinates of two points (i,j) The greatest common divisor of is 1, Then there is no integer lattice on its line )
Code
int gcd(int a, int b)
{
if (!b) return a;
return gcd(b, a % b);
}
ll C(ll x)
{
return x * (x - 1) * (x - 2) / 6;
}
int main()
{
IOS;
ll n, m;
cin >> n >> m;
n++; m++;
ll ans = C(n * m);
ans -= n * C(m) + m * C(n);
for (int i = 1; i < n; i++)
for (int j = 1; j < m; j++)
ans -= (n - i) * (m - j) * (gcd(i, j) - 1) * 2;
cout << ans << endl;
return 0;
}
边栏推荐
- Mysql_ Note1
- 【Verilog数字系统设计(夏宇闻)4-----Verilog语法的基本概念2】
- In spark SQL, date is used to display the day of the week according to the year, month and day_ format(date,‘u‘)
- IP address of the network
- poj1521
- Test questions and answers of the latest Beijing Construction eight (materialman) mock examination in 2022
- 3059. Sculpture (jzoj)
- 大佬们, flinksql datahub源表,源表有字段 timestamp 16位, 写入Ora
- Is it safe to buy funds in stock accounts? Professional answers
- npm ERR! code ETIMEDOUTnpm ERR! syscall connectnpm ERR! errno ETIMEDOUTnpm ERR! network request t
猜你喜欢

Overview of database stress testing methods

Iftnews | suppose this is what the metauniverse looks like 20 years later

CPU的三种模式

Format JS code and debug JS code

6 + 1 skills of Software Test Engineer

Cross Site Request Forgery (CSRF): impact, examples, and Prevention

Understand Linglong platform unified access service from simple to deep Monet

推荐系统-协同过滤在Spark中的实现

Nodejs builds cloud native microservice applications based on dapr, a quick start guide from 0 to 1

SVN版本控制分支、合并功能使用
随机推荐
Cross Site Request Forgery (CSRF): impact, examples, and Prevention
SVN版本控制分支、合并功能使用
How does Flink SQL configure to print the insert parameter log
Leetcode/ numbers that appear only once
NFT market also began to diversify
大咖观点+500强案例,软件团队应该这样提升研发效能
leetcode/只出现一次的数字
大佬们, flinksql datahub源表,源表有字段 timestamp 16位, 写入Ora
QTreeWidget虚线设置
Proto conversion dart | project uses protobuf | fluent uses grpc
Understand Linglong platform unified access service from simple to deep Monet
Google gson usage details
FFT用于估计插值后的图像重采样因子
Fiddler5+ lightning simulator 4.0 settings for app packet capturing
Zombie's treasure test (enumeration)
Speech comprehension center comprehension summary
“蔚来杯“2022牛客暑期多校训练营2 H.[Take the Elevator] 维护线段
My Mysql to MySQL data table synchronization, only the code written in the first order will take effect, and the rest will not take effect. This may be
y77.第四章 Prometheus大厂监控体系及实战 -- prometheus的服务发现机制(八)
Image batch processing Gaussian filter noise reduction + peak signal-to-noise ratio calculation