2016
Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 363 Solved: 219
[ Submit][ Status][ Web Board]
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
HINT
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
LL a[3000],b[3000],n,m;
int main()
{
while(~scanf("%I64d %I64d",&n,&m))
{
memset(a,0,sizeof a);
memset(b,0,sizeof b);
LL temp=n/2016;
LL cnt=n%2016;
a[0]=temp;
for(int i=1; i<=cnt; i++) a[i]=temp+1;
for(int i=cnt+1; i<2016; i++) a[i]=temp;
temp=m/2016;
cnt=m%2016;
b[0]=temp;
for(int i=1; i<=cnt; i++) b[i]=temp+1;
for(int i=cnt+1; i<2016; i++) b[i]=temp;
LL ans=0;
for(int i=0; i<2016; i++)
{
for(int j=0; j<2016; j++)
if((i*j)%2016==0) ans+=a[i]*b[j];
}
printf("%lld\n",ans);
}
return 0;
}