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, 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
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;
 const int MAX = +;
 const LL MOD = 1LL<<;
 LL dp[MAX],ans[MAX];
 void gao1() {
     for(int i=;i<MAX;i++) {
         for(int j=i;j<MAX;j+=i) {
             ans[j]+=(LL)(j/i+)*(j/i)/2LL;
         }
     }
 }
 void init() {
     memset(dp,,sizeof(dp)); dp[]=;
     for(int i=;i<MAX;i++) {
         dp[i]=(dp[i-]+(LL)ans[i]*(LL)i)%MOD;
     }
 }
 int main() {
     //printf("%I64d\n",MOD);
     int cas,n,cnt=;
     gao1(); init();
     scanf("%d",&cas);
     while(cas--) {
         scanf("%d",&n);
         printf("Case #%d: %I64d\n",++cnt,dp[n]);
     }
     return ;

36 }

HDU 4944的更多相关文章

  1. hdu 4944 FSF’s game(数论)

    题目链接:hdu 4944 FSF's game 题目大意:给定N,能够用不大于N的长a和宽b.组成N∗(N−1)2种不同的矩形,对于每一个矩形a∗b要计算它的值,K为矩形a,b能够拆分成若干个K∗K ...

  2. HDU 4944 逆序数对

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 题意: 给出一个序列,可以相邻的交换k次,求 k 次之后,逆序数对最少是多少: 分析: 可以发现 ...

  3. HDU 4944 FSF’s game(2014 Multi-University Training Contest 7)

    思路:  ans[n]=  ans[n-1] + { (n,1),(n,2).....(n,n)}  现在任务 是 计算  { (n,1),(n,2).....(n,n)}(k=n的任意因子) 很明显 ...

  4. HDU 4944 FSF’s game 一道好题

    FSF’s game Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tota ...

  5. HDU - 4944 FSF’s game

    Problem Description FSF has programmed a game. In this game, players need to divide a rectangle into ...

  6. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  8. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. JAVA中abstract,interface,final,static语法

    转自:http://www.cnblogs.com/yueue/archive/2010/04/20/1715863.html 一,抽象类:abstract     1,只要有一个或一个以上抽象方法的 ...

  2. 关于C# DropDownList 动态加载数据笔记

    今天在处理一个导游注册的页面,其中需要填写地址以及该地址下所有旅行社,地址区级以上都是用下拉列表实现,具体地址街道等手动填写.在填写区县之后,该区县下的所有旅行社也需要动态加载. 后台代码 DataT ...

  3. AJPFX实践 java实现快速排序算法

    快速排序算法使用的分治法策略来把一个序列分为两个子序列来实现排序的思路: 1.从数列中挑出一个元素,称为“基准“2.重新排序数列,所有元素比基准值小的摆放在基准前面,所有元素比基准值大的摆在基准的后面 ...

  4. leetcode764 Largest Plus Sign

    思路: 首先使用dp计算出在每个位置(i, j)上下左右最多有多少个连续的1,得到up[i][j], down[i][j], left[i][j], right[i][j].然后计算这四个值中的最小值 ...

  5. 1775. [国家集训队2010]小Z的袜子

    [题目描述] 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命…… 具体来说,小Z把这N只袜子从1到 ...

  6. 30款jQuery常用网页焦点图banner图片切换

    1.jquery 图片滚动特效制作 slide 图片类似窗帘式图片滚动 查看演示 2.jquery幻灯片插件带滚动条的圆形立体图片旋转滚动 查看演示 3.jQuery图片层叠旋转类似洗牌翻转图片幻灯片 ...

  7. Prim算法以及Kruskal算法

    Prim算法主要用于计算最小生成树.算法在选取最小路径的时候需要优化,算法思路:从某个顶点开始,假设v0,此时v0属于最小生成树结点中的一个元素,该集合假设V,剩下的点待选择的点为U,然后找寻V中的点 ...

  8. spark shuffle参数及调优建议(转)

    原文:http://www.cnblogs.com/arachis/p/Spark_Shuffle.html spark.shuffle.file.buffer 默认值:32k 参数说明:该参数用于设 ...

  9. SQL转Java代码小工具

    工作中使用SQL的时候很多,当使用hibernate的时候,经常遇到多行的SQL,通常在PL/SQL或其他地方写好SQL,测试没问题后,需要将SQL写到程序代码中,多行SQL需要拼接字符串,手动一行行 ...

  10. (三)Redis for StackExchange.Redis

    目录 (一)Redis for Windows正确打开方式 (二)Redis for 阿里云公网连接 (三)Redis for StackExchange.Redis StackExchange.Re ...