2016湖南省赛-A-2016 (思路)

xiaoxiao2021-02-28  87

Problem A: 2016

Time Limit: 5 Sec  Memory Limit: 128 MB

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 思路: 1、任何一个数都能表示成n=a*2016+i,m=b*2016+j; 则n*m=a*b*2016^2+a*2016*j+b*2016*i+i*j;如果i*j是2016的倍数的话,那么n*m一定是2016的倍数若i*j == 0 先把a和b为2016的倍数的情况筛出出去——容斥方法否则 在2015*2015的规模中遍历出符合i*j 16=0的数,按照n中有多少个这样的i,m中有多少这样的j,然后相乘,累加起来就得到的区间中所有的数 Select Code #include <iostream> #include <cstdio> #include <algorithm> using namespace std; int main() { long long n,m; while(cin >> n>> m) { long long ans = (n/2016)*m + (m/2016)*n - (n/2016)*(m/2016); for(int i = 1; i <= min(n,(long long) 2015);i++) for(int j = 1; j <= min(m,(long long) 2015);j++) { if((i*j) 16 == 0) ans += ((n-i)/2016 + 1)*((m-j)/2016 + 1); } cout << ans <<endl; } return 0; }
转载请注明原文地址: https://www.6miu.com/read-61474.html

最新回复(0)