CSU 1803 2016 湖南省2016省赛

1803: 2016

        Time Limit: 5 Sec     Memory Limit: 128 Mb     Submitted: 1416     Solved: 815    


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

Source

湖南省第十二届大学生计算机程序设计竞赛
 
逆向思维 你只需要考虑不是2016倍数的数有多少个
 
a×b%2016!=0 
a%2016!=0b%2016!=0 
ab2016 
a%2016=i,b%2016=j 
i×j%2016!=0 
ans=((ni)/2016+1)×((mj)/2016+1)
 
参考博客 http://blog.csdn.net/miracle_ma/article/details/52425794
 
#include<iostream>
using namespace std;
#define LL long long
int main(){
    int n,m;
    while(cin>>n>>m){
        LL ans=(LL)n*m;
        for(int i=1;i<=min(2015,n);i++){
            for(int j=1;j<=min(2015,m);j++){
                if(i*j%2016!=0){
                    ans-=(LL)((n-i)/2016+1)*((LL)(m-j)/2016+1);
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

 

posted on 2017-07-31 16:08  九月旧约  阅读(138)  评论(0编辑  收藏  举报

导航