Test Instructions
given positive integers n and m, count the number of positive integer pairs (A, b) that meet the following conditions:
1.1≤a≤n, 1≤b≤m;
2. AXB is a multiple of 2016.
Sample Input
About
to
1000000000 1000000000
Sample Output
1
30576
7523146895502644
Ideas
can be obtained by the congruence formula
A * b = (a) * (b)%
so if X*y is a multiple of 2016, then (2016*k + x) *y is also
It is only necessary to count the number of occurrences of the remainder of each modulo 2016 of the 1-n to reduce the number of cycles in the enumeration to 2016*2016.
1#include <cstdio>2typedefLong Long intLL;3 Const intN = .;4 intA[n], b[n];5 LL ans;6 intMainvoid)7 {8 intN, M, NX, MX;9 while(~SCANF ("%d%d", &n, &m))Ten { OneNX = N/N; Amx = m/N; - for(intI=0; i<n; ++i) -A[i] = NX, b[i] =MX; theNX = n%N; -mx = m%N; - for(intI=1; i<=nx; ++a[i++]); - for(intI=1; i<=mx; ++b[i++]); +Ans =0; - for(intI=0; i<n; ++i) + for(intj=0; j<n; ++j) A if(i*j%n = =0) atAns + = (LL) a[i] *B[j]; -printf"%lld\n", ans); - } - return 0; -}
CSU 1803 2016 (congruence formula) 2016 Hunan Province 12th session of college students computer Program design Competition