1803: 2016
Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 399 Solved: 245
[ 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
题解:a*b%mod=(a%mod)*(b%mod),于是可以在2016内枚举i,j,如果i*j%2016==0,那么组合的个数=n内模2016等于i的数的个数*m内模2016等于j的数的个数
#include<cstdio>
#include<queue>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long LL;
int main(){
LL n,m;
while(~scanf("%lld%lld",&n,&m)){
LL mn=min(2016ll,n),mm=min(2016ll,m);
LL ans=0;
for(LL i=1;i<=mn;i++){
LL c1=(n-i)/2016+1;
for(LL j=1;j<=mm;j++){
LL c2=(m-j)/2016+1;
if(i*j%2016==0) ans+=c1*c2;
}
}
printf("%lld\n",ans);
}
}