Description
给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量:
1. 1≤a≤n,1≤b≤m;
2. a×b 是 2016 的倍数。
Input
输入包含不超过 30 组数据。
每组数据包含两个整数 n,m (1≤n,m≤10 9).
Output
对于每组数据,输出一个整数表示满足条件的数量。
Sample Input
32 63
2016 2016
1000000000 1000000000
Sample Output
1
30576
7523146895502644
[分析]
n和m比较大,所以肯定从小的数字入手,就是2016
根据同余,如果a和b都小于2016,并且a*b%2016==0,那么,a或b加上多个2016,取模还是等于0.
所以我们可以先求出2016以内有多少个满足的式子,然后算n里面有多少个与a同余,m里面有多少个与b同余。两个数量相乘,然后加到ans,就是答案了。
[代码]
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int a, b;
while (scanf("%d%d", &a, &b) != EOF)
{
long long ans = 0;
for (int i = 1; i <= min(a, 2016); i++)
{
;
for (int j = 1; j <= min(b, 2016); j++)
{
if ((i*j)%2016 == 0)
{
long long numa = a / 2016;
long long numb = b / 2016;
if (a % 2016 >= i)numa++;
if (b % 2016 >= j)numb++;
ans += numa*numb;
}
}
}
printf("%lld\n", ans);
}
}