CSU1803 (简单同余定理)

版权声明:Dream_dog专属 https://blog.csdn.net/Dog_dream/article/details/82632547

Description

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

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

2. a×b 是 2016 的倍数。

扫描二维码关注公众号,回复: 3231054 查看本文章

Input

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

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

Output

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

Sample Input

32 63
2016 2016
1000000000 1000000000

Sample Output

1
30576
7523146895502644

非常水的一道题   最近脑袋秀逗了  存下来  视警


#include<iostream>
#include<cstdio>
using namespace std;
#define MAX_N   10000+2
#define clr(a,b) memset(a,b,sizeof(a))
typedef long long ll;
const ll maxn=1e5+1;
int main()
{
    ll m,n;
    while(~scanf("%lld%lld",&n,&m))
    {
     ll a[maxn]={0},b[maxn]={0},ans=0;
     for(int i=0;i<2016;i++)
     {
      a[i]=n/2016;b[i]=m/2016;
      if(n%2016>=i){a[i]++;}
      if(m%2016>=i){b[i]++;}
     }
     a[0]--;b[0]--;
     for(int i=0;i<2016&&a[i==0?1:i];i++)
     {
       for(int j=0;j<2016&&b[j==0?1:j];j++)
       {
         if(i*j%2016==0){ans+=a[i]*b[j];}
       }
     }
     printf("%lld\n",ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Dog_dream/article/details/82632547