zoukankan      html  css  js  c++  java
  • HDU 4944

    FSF’s game


    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, 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
    Output a single line for each test case.

    For each test case, you should 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
    3 1 3 100
     

    Sample Output
    Case #1: 1 Case #2: 30 Case #3: 15662489

     题意:很容易了 ,求  : A*B/gcd(A/K,B/K) 的值。

    sl :很容易知道 k必须是 a,b 的因子。然后A B 设  C=gcd(A,B)/k  .   可以知道  C为gcd(A,B)的所有因子。  求gcd(i,n) 的因子等价于先筛出所有n的因子。

    然后由于 因子 能整除i 所以 i 必然是 1*k,2*k,3*k,4*k......n*k . 所以所有的 因子为  i的和为 (1+2+3+4+、、、+n/i) .剩下的dp能搞了。。。。。

    orz推出来的神犇 ,杂家不会啊。悲伤。。。

     1 // by caonima
     2 // hehe
     3 #include <cstdio>
     4 #include <cstring>
     5 #include <algorithm>
     6 #include <vector>
     7 #include <map>
     8 using namespace std;
     9 typedef long long LL;
    10 const int MAX = 500000+10;
    11 const LL MOD = 1LL<<32;
    12 LL dp[MAX],ans[MAX];
    13 void gao1() {
    14     for(int i=1;i<MAX;i++) {
    15         for(int j=i;j<MAX;j+=i) {
    16             ans[j]+=(LL)(j/i+1)*(j/i)/2LL;
    17         }
    18     }
    19 }
    20 void init() {
    21     memset(dp,0,sizeof(dp)); dp[1]=1;
    22     for(int i=2;i<MAX;i++) {
    23         dp[i]=(dp[i-1]+(LL)ans[i]*(LL)i)%MOD;
    24     }
    25 }
    26 int main() {
    27     //printf("%I64d ",MOD);
    28     int cas,n,cnt=0;
    29     gao1(); init();
    30     scanf("%d",&cas);
    31     while(cas--) {
    32         scanf("%d",&n);
    33         printf("Case #%d: %I64d ",++cnt,dp[n]);
    34     }
    35     return 0;

    36 } 

  • 相关阅读:
    有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。
    C编程实现2的1000次方(使程序中的n=1000即可)
    有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面m个数。
    有一个字符串,内有若干字符,输入一个字符,要求程序将字符串中该字符删去。
    使用静态变量的方法求n!
    数组排序:冒泡法和选择法
    使用函数的递归调用来解决Hanoi(汉诺)塔问题。
    VC5509的通用GEL代码
    字、字节和位的关系
    安装JDK后环境变量的配置
  • 原文地址:https://www.cnblogs.com/acvc/p/3908398.html
Copyright © 2011-2022 走看看