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: 15662489HintIn 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
题意:给你个n,让你求在n的范围内。是否能将一个矩形分成若干个同样大小为k的正方形,相应有val值,让你统计在n内的全部可能的分数总值
思路:首先我们来试着求解∑i=1nn∗igcd(nk,ik),那么我们能够确定的是假设能够把n∗m的矩形分成大小为k的正方形的话,那么k一定是gcd(n,
i)的因子。那么对于一项来说由于公式能够变形
n∗i∗kgcd(n,i)
-> n∗(ic1+ic2+...)
{k枚举全部的可能},那么cj是n的因子,那么icj就是因子相应的系数,我们再从全部的i来讲。对于因子我们能够计算出全部可能的数,比方因子cj,我们能够得到cj,
2∗cj,
3∗cj,
4∗cj....n,那么相应的系数就是我们须要的icj,累加起来计算是:
num[cj]=(1+2+...+ncj)=(1+ncj)∗(ncj)2
val[n]=∑i=1nnum[i]
ans[n]=ans[n−1]+val[n]
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll __int64
using namespace std;
const int maxn = 500005;
const ll mod = 1ll<<32; ll num[maxn], dp[maxn]; void cal() {
for (ll i = 1; i < maxn; i++)
for (ll j = i; j < maxn; j += i)
num[j] += (j/i+1) * (j/i) / 2;
} void init() {
memset(num, 0, sizeof(num));
cal();
dp[1] = 1;
for (ll i = 2; i < maxn; i++) {
dp[i] = dp[i-1] + num[i]*i;
dp[i] = dp[i] % mod;
}
} int main() {
init();
int t, n, cas = 1;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
printf("Case #%d: %I64d\n", cas++, dp[n]);
}
return 0;
}
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 一道好题
FSF’s game Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tota ...
- 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 逆序数对
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 题意: 给出一个序列,可以相邻的交换k次,求 k 次之后,逆序数对最少是多少: 分析: 可以发现 ...
- HDU 4944
FSF’s game Problem Description FSF has programmed a game.In this game, players need to divide a rect ...
- HDOJ 4944 FSF’s game
http://blog.csdn.net/keshuai19940722/article/details/38519681 不明真相的补一发... FSF's game Time Limit: 900 ...
- 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 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
随机推荐
- javaScript 网页特效 输出语句
大家好,我是小强老师,今天主要讲解 三个最为常用的输出语句. alert() 弹出警示框 window.alert(‘继续学习’); 完整的写法 效果如下: 因为alert 属于window 对象 ...
- MVC中Controller里写alert的问题
controller: Viewbag.a=true; 页面中 @if(Viewbag.a!=null) { <script> alert('XXX'); </script> ...
- php利用iframe实现无刷新文件上传功能
上传原理很简单就是利用表单的打开方式为iframe的name名,这样就可以在当前页面的iframe打来了,实现文件上传,再利用js返回上传结果. form target .在 action 属性中规定 ...
- 海量数据处理算法—Bloom Filter
海量数据处理算法—Bloom Filter 1. Bloom-Filter算法简介 Bloom-Filter,即布隆过滤器,1970年由Bloom中提出.它可以用于检索一个元素是否在一个集合中. Bl ...
- 解决TCP网络传输“粘包”问题
当前在网络传输应用中,广泛采用的是TCP/IP通信协议及其标准的socket应用开发编程接口(API).TCP/IP传输层有两个并列的协议:TCP和UDP.其中TCP(transport contro ...
- HTMLParser-简单HTML和XHTML解析
使用HTMLParser模块解析HTML页面 HTMLParser是python用来解析html和xhtml文件格式的模块.它可以分析出html里面的标签.数据等等,是一种处理html的简便途径.HT ...
- SystemTap----将SystemTap脚本编译成内核模块
当运行SystemTap脚本时,会根据脚本生成一个内核模块,然后插入到系统中执行后退出.这个过程总共分为5个阶段:parse, elaborate, translate, compile, run ...
- 【C语言】数字在排序数组中出现的次数(改动)
//数字在排序数组中出现的次数(改动) //统计一个数字在排序数组中出现的次数.比如:排序数组{1,2,3,3,3.3,4,5}和数字3,因为3出现了4次,因此输出4. #include <st ...
- SQL SERVER 2008R2sp1配置Database Mail –用SQL 数据库发邮件
步骤1)创建配置文件和帐户 看图片吧,挺简单的: 中间略过的一些步骤,就点下一步即可. 下面我们测试一下: Step 2)配置邮件: 在完成账户和配置文件创建之后,我们需要配置Database Mai ...
- ArrayList集合-[习题]--C#
:向集合中添加10个元素,计算平均值,求最大.最小值. ; list.AddRange(, , , , , , , , }); int Max, Min; Max = Min = (]; ; i &l ...