HDOJ 4944 FSF's game

Source: Internet
Author: User

HDOJ 4944 FSF's game

 

FSF's game Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission (s): 448 Accepted Submission (s): 215



Problem Description FSF has programmed a game.
In this game, players need to divide a rectangle into several same squares.
The length and width of rectangles are integer, and of course the side length of squares are integer.

After division, players can get some coins.
If players successfully divide a AxB rectangle (length: A, width: B) into KxK squares (side length: K), they can get A * B/gcd (A/K, b/K) gold coins.
In a level, you can't get coins twice with same method.
(For example, You can get 6 coins from 2x2 (A = 2, B = 2) rectangle. when K = 1, A * B/gcd (A/K, B/K) = 2; When K = 2, A * B/gcd (A/K, b/K) = 4; 2 + 4 = 6 ;)

There are N * (N + 1)/2 levels in this game, and every level is an unique rectangle. (1x1, 2x1, 2x2, 3x1 ,..., nx (N-1), NxN)

FSF has played this game for a long time, and he finally gets all the coins in the game.
Unfortunately, he uses an UNSIGNED 32-bit integer variable to count the number of coins.
This variable may overflow.
We want to know what the variable will be.
(In other words, the number of coins mod 2 ^ 32)
Input There are multiply test cases.

The first line contains an integer T (T <= 500000), the number of test cases

Each of the next T lines contain an integer N (N <= 500000 ).
Output a single line for each test case.

For each test case, you shoshould output Case # C:. first, where C indicates the case number and counts from 1.

Then output the answer, the value of that UNSIGNED 32-bit integer variable.
Sample Input
313100

Sample Output
Case #1: 1Case #2: 30Case #3: 15662489HintIn the second test case, there are six levels(1x1,1x2,1x3,2x2,2x3,3x3)Here is the details for this game:1x1: 1(K=1); 1x2: 2(K=1); 1x3: 3(K=1);  2x2: 2(K=1), 4(K=2); 2x3: 6(K=1); 3x3: 3(K=1), 9(K=3); 1+2+3+2+4+6+3+9=30 

Author UESTC
Source 2014 Multi-University Training Contest 7

 

 

 

 

#include 
 
  #include 
  
   #include 
   
    #include using namespace std;typedef long long int LL;const int maxn=500050;const LL mod=1LL<<32;LL f[maxn],s[maxn];void init(){    for(int i=1;i
    
     

 

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.