Description

给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量:

  1. 1≤a≤n,1≤b≤m;

  2. a×b 是 2016 的倍数。
    Input

输入包含不超过 30 组数据。

每组数据包含两个整数 n,m (1≤n,m≤109).

Output

对于每组数据,输出一个整数表示满足条件的数量。

Sample Input

32 63

2016 2016

1000000000 1000000000

Sample Output

1

30576

7523146895502644

解法: a*b是2016的倍数,直接枚举不可能,容易想到用2个长度为2016的数组记录n和m模上2016为i的个

数,然后暴力枚举就可以了。复杂度O(2016^2)

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2020;
int a[maxn], b[maxn];
LL n, m;
int main()
{
while(scanf("%lld%lld", &n,&m)!=EOF)
{
for(int i=0; i<2016; i++){
a[i]=n/2016;
if(n%2016>=i){
a[i]++;
}
b[i]=m/2016;
if(m%2016>=i){
b[i]++;
}
}
a[0]--;
b[0]--;
LL ans=0;
for(int i=0; i<2016; i++){
for(int j=0; j<2016; j++){
if(i*j%2016==0){
ans+=1LL*a[i]*b[j];
}
}
}
printf("%lld\n", ans);
}
return 0;
}