CSUOJ—1803

来源:互联网 发布:手机签字软件 编辑:程序博客网 时间:2024/06/07 06:28

A - 2016

 
 给出正整数 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 632016 20161000000000 1000000000
Sample Output
1305767523146895502644
【分析】
a*b%2016=0,预处理一下a,b中分别有多少个1的倍数,2的倍数,3的倍数...
然后枚举一下2016*2016就可以了......
【代码】
#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>using namespace std; long long a[3000];long long b[3000];int main()  {      long long n,m;while(~scanf("%lld%lld",&n,&m))      {          for(int i=0;i<2016;i++) a[i]=n/2016,b[i]=m/2016;          for(int i=1;i<=n%2016;i++) a[i]++;          for(int i=1;i<=m%2016;i++) b[i]++;          long long 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;  }  


原创粉丝点击