CSU1803——2016(思路)

来源:互联网 发布:淘宝直播大v通道 编辑:程序博客网 时间:2024/05/01 11:15

1803: 2016

        Time Limit: 5 Sec     Memory Limit: 128 Mb     Submitted: 1201     Solved: 689    

Description

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

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

2. a×b 是 2016 的倍数。

Input

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

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

Output

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

Sample Input

32 632016 20161000000000 1000000000

Sample Output

1305767523146895502644

Hint

Source

湖南省第十二届大学生计算机程序设计竞赛
思路:a*b%2016==0  那么(a%2016) * (b%2016)==0
也就是说,n和m中各有多少模2016的余数满足i*j%2016==0,这些数量相乘即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <stack>
using namespace std;
typedef long long ll;
#define PI 3.1415926535897932
#define E 2.718281828459045
#define INF 0xffffffff//0x3f3f3f3f
#define mod 1000000007
const int MOD=1e9+7;

const int M=1005;
int n,m;
int a[2016],b[2016];
void init(int n,int m)
{
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(int i=1; i<=2016; i++)
    {
        a[i]=n/2016;
    }
    for(int i=1; i<=n%2016; i++)
    {
        a[i]++;
    }
    for(int i=1; i<=2016; i++)
    {
        b[i]=m/2016;
    }
    for(int i=1; i<=m%2016; i++)
    {
        b[i]++;
    }
}
int main()
{
    int i,j,k,t;
    while(~scanf("%d%d",&n,&m))
    {
        /*for(i=1; i*i<=2016; i++)
            if(2016%i==0)
                printf("%d %d\n",i,2016/i);*/
        init(n,m);
            ll ans=0;
        for(i=1; i<=2016; i++)
            for(j=1; j<=2016; j++)
                if((i*j)%2016==0)
                {
                    ans+=(ll)a[i]*b[j];
                    //printf("%d %d\n",i,j);
                }
        printf("%I64d\n",ans);
    }
    return 0;
}
0 0
原创粉丝点击