2016(表达形式的转化)

来源:互联网 发布:网络是个虚拟世界英语 编辑:程序博客网 时间:2024/05/28 09:32

Time limit5000 msMemory limit131072 kB

给出正整数 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表示为 n=2016*k+r1,n2=2016*k+r2
n*m%2016=r1*r2;
只要r1*r2%2016==0,相应的 计算出a*b满足题目条件的个数

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int mod=10056;const int N=1e5+5;typedef long long LL;#define mem(a,n) memset(a,n,sizeof(a))int main(){    LL n,m;    while(~scanf("%lld%lld",&n,&m))    {        LL min1=min(n,2016LL),min2=min(m,2016LL);        LL ans=0;        for(LL r1=1; r1<=min1; r1++)///这里不能取[0,min1),例如 样例1,30*63==2016             for(LL r2=1; r2<=min2; r2++)            {                if((r1*r2)%2016==0)                    ans=ans+((n-r1)/2016+1)*((m-r2)/2016+1);            }        printf("%lld\n",ans);    }    return 0;}
原创粉丝点击