Hdu4944fsf's game (number theory)

Source: Internet
Author: User

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 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.