csu----A(1803): 2016

A(1803): 2016题目

Submit Page    Summary    Time Limit: 5 Sec     Memory Limit: 128 Mb     Submitted: 15     Solved: 12    


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 63
2016 2016
1000000000 1000000000

Sample Output

1
30576
7523146895502644

Hint

n=a*2016+i

m=b*2016+j

n*m=a*b*2016^{2} + a*j*2016 + b*i*2016 + i*j

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
int main()
{
    ios::sync_with_stdio(false);
    ll n,m;
    while(~scanf("%lld%lld",&n,&m))
    {
        ll ans=(n/2016)*m+(m/2016)*n-(n/2016)*(m/2016);
        for(ll i=1;i<=min(n,(ll)2015);i++)
        for(ll j=1;j<=min(m,(ll)2015);j++)
        {
            if((i*j)%2016==0)
            {
                ans+=((n-i)/2016+1)*((m-j)/2016+1);
            }
        }
        printf("%lld
",ans);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/ke-yi-/p/10175817.html