http://blog.csdn.net/keshuai19940722/article/details/38519681

不明真相的补一发。。。

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
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
Hint
In 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
 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> 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<maxn;i++)
{
for(int k=1;k*i<maxn;k++)
{
f[i*k]+=(1LL+k)*k/2;
f[i*k]%=mod;
}
f[i]=f[i]*i;
f[i]%=mod;
}
for(int i=1;i<maxn;i++)
{
s[i]=(f[i]+s[i-1])%mod;
}
} int main()
{
init();
int T_T,cas=1;
scanf("%d",&T_T);
while(T_T--)
{
int x;
scanf("%d",&x);
printf("Case #%d: %lld\n",cas++,s[x]);
}
return 0;
}

HDOJ 4944 FSF’s game的更多相关文章

  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 FSF’s game 一道好题

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

  3. HDU - 4944 FSF’s game

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

  4. 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的任意因子) 很明显 ...

  5. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  7. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  8. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  9. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

随机推荐

  1. PowerShell攻防进阶篇:nishang工具用法详解

    PowerShell攻防进阶篇:nishang工具用法详解 导语:nishang,PowerShell下并肩Empire,Powersploit的神器. 开始之前,先放出个下载地址! 下载地址:htt ...

  2. subprocess学习

    转自http://blog.csdn.net/imzoer/article/details/8678029 subprocess的目的就是启动一个新的进程并且与之通信. subprocess模块中只定 ...

  3. 【BZOJ3926】【ZJOI2015】诸神眷顾的幻想乡 广义后缀自动机

    题目: 题目在这里 思路&做法: 参考的题解 既然只有\(20\)个叶子节点, 那么可以从每个叶子节点往上建一颗\(trie\)树, 然后合并成一棵大的\(trie\)树, 然后构建广义后缀自 ...

  4. SQL Server阻塞诊断

    在数据仓库维护过程中,经常会出现定时更新程序和查询SQL发生冲突而引起阻塞的情况,需要进行SQL Server诊断. SQL Server诊断一般会用到2个视图:sys.sysprocesses(系统 ...

  5. jQuery Validate前端验证

    我们经常看到如下效果,那么它是如何实现的呢?看下面: 废话少说,直接上代码,大家直接Copy就能看到上面的效果啦. <html> <head> <title>验证内 ...

  6. 5个对话框和FileStream:文件流

    1.private void button1_Click(object sender, EventArgs e) { colorDialog1.ShowDialog();//显示颜色选择器 panel ...

  7. 单元测试之Mock

    为什么需要Mock. 真实对象具有不确定的行为.所以会产生不可预测的结果. 真实对象很难被创建. 真实对象的某些行为很难被触发(如网络错误). 真实对象令程序的运行速度很慢. 真实对象有(或者是)用户 ...

  8. Java学习-课堂总结

    一.字符串比较方式 1)‘==’   地址值比较      2) equals()方法   内容比较 二.String类的两种实例化方式     1)String str=“Hello”:     2 ...

  9. [转]C++内存管理

    [导语] 内存管理是C++最令人切齿痛恨的问题,也是C++最有争议的问题,C++高手从中获得了更好的性能,更大的自由,C++菜鸟的收获则是一遍一遍的检查代码和对C++的痛恨,但内存管理在C++中无处不 ...

  10. 用JS解决Asp.net Mvc返回JsonResult中DateTime类型数据格式的问题

    当用ajax异步时,返回JsonResult格式的时候,发现当字段是dateTime类型时,返回的json格式既然是“/Date(1435542121135)/” 这样子的,当然这不是我们想要的格式. ...