HDU 4944 FSF’s game 一道好题
FSF’s game
Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 727 Accepted Submission(s):
377
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)
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).
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.
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
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef __int64 LL; const int maxn = 5e5+;
LL p = ;
LL dp[maxn];
void init()
{
int j,tmp;
for(j=;j<=;j++)p=p*; for(int i=;i<maxn;i++){
tmp = i;
for(j=;(tmp=i*j)<maxn;j++){
dp[tmp]=(dp[tmp]+((LL)(+j)*(LL)j)/)%p;
}
}
dp[]=;
for(int i=;i<maxn;i++){
dp[i]=(dp[i-]+dp[i]*i)%p;
}
}
int main()
{
int T,n;
init();
scanf("%d",&T);
for(int t=;t<=T;t++)
{
scanf("%d",&n);
printf("Case #%d: %I64d\n",t,dp[n]);
}
return ;
}
HDU 4944 FSF’s game 一道好题的更多相关文章
- 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 ...
- HDU - 4944 FSF’s game
Problem Description FSF has programmed a game. In this game, players need to divide a rectangle into ...
- 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的任意因子) 很明显 ...
- HDU 2096 小明A+B --- 水题
HDU 2096 /* HDU 2096 小明A+B --- 水题 */ #include <cstdio> int main() { #ifdef _LOCAL freopen(&quo ...
- HDU 1248 寒冰王座(全然背包:入门题)
HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...
- hdu 5071(2014鞍山现场赛B题,大模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 思路:模拟题,没啥可说的,移动的时候需要注意top的变化. #include <iostr ...
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- HDU 2577 How to Type(dp题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2577 解题报告:有一个长度在100以内的字符串,并且这个字符串只有大写和小写字母组成,现在要把这些字符 ...
- [HDU 2602]Bone Collector ( 0-1背包水题 )
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 水题啊水题 还给我WA了好多次 因为我在j<w[i]的时候状态没有下传.. #includ ...
随机推荐
- javascript平时小例子③(setInterval使用1)
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- BOM&Navigator对象
<!-- BOM:Brower Object Model 浏览器对象模型 这个模型方便操作浏览器 浏览器对应的对象就是windows对象,这个可以通过查阅DHTML API获得 --> & ...
- Web标准和搜索引擎优化技术
1.Web标准不是某一个标准,而是一系列标准的集合.出来网页内容之外,网页主要由三部分组成:结构(Structure).表现(Presenttation)和行为(Behavior).对应的标准也分三方 ...
- 支付宝C# RSA签名 报系统找不到指定的文件问题解决
做支付宝在线支付模块,安卓和苹果端都没为问题,服务器也能顺利的收到付款异步通知. 在做WEB端支付的时候遇到个奇怪的问题:本地localhost调试支付没问题,代码更新到服务器就出现了未将对象引用设置 ...
- ajax同步、异步执行简单理解与证明
此理解范例代码来自前几篇随笔! 首先我们来先了解下AJAX: Ajax:全称“Asynchronous Javascript and XML”(异步Javascript和XML),他是由Javascr ...
- Avada主题通过自定义CSS全局更换微软雅黑字体
Avada主题的菜单.正文.标题.面包屑路径等等如果想更换为“微软雅黑”中文字体,只需要进入Avada主题的选项,倒数第二项有个Custom CSS,把下面的代码粘贴进去即可.当然你也可以自行改变字体 ...
- 能套用的tab栏切换
效果: 在style.js文件里封装了一个Show函数,有4个参数,di(当前点击的按钮),num(按钮个数,也可以说是下面具体内容个数),divn(一个id前缀,这个例子里是ta,),active( ...
- Android Studio 开发环境设置
修改字体(File=>Settings 按下如所图设计字体) 显示行号.空格 用 制表符 代替 空格 显示 最终代码显示如下图 格式化代码 使用 Ctrl+Alt+L
- Python基础二. 数据结构、控制流、运算符、真值测试
一.概述 数据结构上广义上有两种,单一类型和集合类型 单一类型,表示一种对象 集合类型,表示包含多种对象 Python 中的内建的数据类型有str.list.tuple.dict.set.number ...
- iOS解析JSON字符串报错Error Domain=NSCocoaErrorDomain Code=3840 "Invalid escape sequence around character 586."
将服务器返回的JSON string转化成字典时报错: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid escape sequence ...