HDU 4944
FSF’s 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)
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.
3 1 3 100
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的更多相关文章
- 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 逆序数对
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 题意: 给出一个序列,可以相邻的交换k次,求 k 次之后,逆序数对最少是多少: 分析: 可以发现 ...
- 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 4944 FSF’s game 一道好题
FSF’s game Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tota ...
- HDU - 4944 FSF’s game
Problem Description FSF has programmed a game. In this game, players need to divide a rectangle into ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- 题解报告:hdu1219AC Me
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1219 Problem Description Ignatius is doing his homewo ...
- js中toFixed重写
在测试原生的toFixed发现,它在个浏览器上表现不一致,并且有些值在保留小数时得到的结果并不是想要,如在chrome下测试: 所以针对toFixed方法不准的问题,我们进行方法改造: 主要思路是:对 ...
- 转】Spark SQL 之 DataFrame
原博文出自于: http://www.cnblogs.com/BYRans/p/5003029.html 感谢! Spark SQL 之 DataFrame 转载请注明出处:http://www.cn ...
- 学习笔记 第十二章 CSS3+HTML5网页排版
第12章 CSS3+HTML5网页排版 [学习重点] 正确使用HTML5结构标签 正确使用HTML5语义元素 能够设计符合标准的网页结构 12.1 使用结构标签 在制作网页时,不仅需要使用< ...
- 一种结合hudson的算法自动化测试构想
作者:朱金灿 来源:http://blog.csdn.net/clever101 有时我在思考:未来软件测试的趋势是什么?其实答案和其它行业一样简单:低技术含量的测试工作都将由机器承担,人只能干机器干 ...
- Glide清除缓存
Glide是谷歌推荐的一款加载图片的第三方框架,对内存优化更好,更省资源,他的众多好处,我就不一一描述了,有兴趣的朋友可以百度一下,介绍的还是挺详细的. 今天主要给大家介绍一下关于怎么获取Glide的 ...
- php学习知识点
1.PHP 代码被包含在特殊的起始符和结束符中 <? ?> 2.php的用途 服务端脚本 命令行脚本. 编写桌面应用程序.3.输出语句.文本 echo printf4.$_SERVER 是 ...
- Visual SVN自动给文件加锁
在使用SVN作为版本控制器的时候,在VS里安装VISUALSVN插件,当修改文件公共文件的时候需要先Get Lock,如果对于多次操作这个鼠标操作显得是一些复杂,自动给文件加锁的操作实际是给文件加一个 ...
- 中国版 Office 365 (X-Tenant / Tango) 功能验证报告 - 1 简介
花了点时间做了一次Office 365 X-Tenant的 POC,对过程做了记录和总结,在这里会陆续分享: (一) 简介 这次POC的系统环境是模拟一个公司的生产环境: 1. 公司总部在国外,拥有 ...
- 玩一把redis源码(一):为redis添加自己的列表类型
2019年第一篇文档,为2019年做个良好的开端,本文档通过step by step的方式向读者展示如何为redis添加一个数据类型,阅读本文档后读者对redis源码的执行逻辑会有比较清晰的认识,并且 ...