Question: hdu4944fsf's game (number theory)
Given N, there will be n * (n + 1)/two class rectangles (1*1, 2*1, 2*2 ,... N * 1, N * 2 .. N * n ). divide these matrices into K * k squares of the same size, and you can obtain the gold coins a * B/gcd (
/K, B/K); then, give n and ask about the total gold coins that can be obtained.
Solution: sum (n): N * (n + 1)/sum (n-1) + f (N) :( N * 1, N * 2 ,... N * n) the sum of the coins in these rectangles ).
For example, n = 8: 1*8/gcd (8/1, 1/1) 2*8/gcd (8/1, 2/1) 2*8/gcd (8/2, 2/2 ).... 8*8/gcd (8/1, 8/2) 8*8/gcd (8/2. 8/2), 8*8/gcd (8/4, 8/4), 8*8/gcd (8/8, 8/8)
1*8 2*8/2 @ 2*8 3*8 4*8 4*8/[email protected] 4*8/4 5*8 6*8 6*8/2 @ 7*8 8*8 @ 8*8/2 8*8/4 8*8/8
We can find that gcd (A/K, B/K) is a factor of N. In addition, a = GCD, n = N *.
For GCD =
Available gold coins G (A): 1 * a * N/A + 2 * a * N/A + 3 * a * N/A +... + Na * N/A = (1 + 2 + 3 + n) * n
Then the factor n of the enumerated N is F (n) = sum1. N (G (AI )).
Code:
# Include <cstdio> # include <cstring> typedef unsigned _ int64 ll; const int maxn = 500005; const ll M = 1ll <32; // int1 will overflow ll F1 [maxn]; ll F2 [maxn]; void Init () {for (INT I = 1; I <maxn; I ++) {for (Int J = 1; j * I <maxn; j ++) F1 [I * j] = (F1 [I * j] + (1ll + I) * I/2) % m;} F2 [1] = 1; for (INT I = 2; I <maxn; I ++) f2 [I] = (F2 [I-1] + F1 [I] * I) % m;} int main () {int t; int N; Init (); scanf ("% d", & T); For (INT I = 1; I <= T; I ++) {scanf ("% d", & N ); printf ("case # % d: % i64u \ n", I, F2 [N]);} return 0 ;}