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 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
题意:给你个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 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
随机推荐
- Delphi资源大全
A curated list of awesome Delphi frameworks, libraries, resources, and shiny things. Inspired by awe ...
- linux学习: sudo命令(ubuntu)
使用 sudo 命令可以提高命令的执行权限,以root权限执行 如 : sudo vi xxx 但是有些内置命令 如 cd 无法通过 sudo来执行 ,如 sudo cd xxx 这是会报错的. ...
- 17.1.1.7 Setting Up Replication with New Master and Slaves 设置复制对于新的Master和Slaves:
17.1.1.7 Setting Up Replication with New Master and Slaves 设置复制对于新的Master和Slaves: 最简单和最直接的方法是设置复制用于使 ...
- Arachnid包含一个简单的HTML剖析器能够分析包含HTML内容的输入流
Arachnid是一个基于Java的web spider框架.它包含一个简单的HTML剖析器能够分析包含HTML内容的输入流.通过实现Arachnid的子类就能够开发一个简单的Web spiders并 ...
- HapiJS开发手冊
HapiJS开发手冊 作者:chszs.转载需注明.博客主页:http://blog.csdn.net/chszs 一.HapiJS介绍 HapiJS是一个开源的.基于Node.js的应用框架,它适用 ...
- 给刚通过51入门的新人讲讲S12(MCS12XS128)与51的差别
MCS51是keil也对应地做好了非常多,也就是有非常多对你而言是透明的,是你不必关心的,你所要接触的寄存器数量也非常小,在这个时候你很多其它是写函数,仅仅只是针对这个平台写C程序比在PC上写C控制台 ...
- webform--常用的控件
一.简单控件 1.Lable——标签:在网页中呈现出来的时候会变成span标签 属性:Text——标签上的文字 BackColor,ForeColor——背景色,前景色 Font——字体 Bold- ...
- jQuery 快速结束当前动画
当需要快速结束一个当前正在执行的jquery 动画时(还没执行完成),如 fadeOut(),可以在执行当前动画的对象上执行 stop(true);方法 如: <script type=&quo ...
- Arcgis镶嵌数据集java代码操作
转自:http://www.cdtarena.com/javapx/201307/9105.html 镶嵌数据集结合了之前arcgis管理影像的栅格目录和栅格数据集,为解决海量影像管理提供了很好的方案 ...
- 高级特性(7)- 高级AWT
7.1 绘图操作流程7.2 形状7.3 区域7.4 笔划7.5 着色7.6 坐标变换7.7 剪切7.8 透明与组合7.9 绘图提示7.10 图像的读取器和写入器 7.10.1 获得图像文件类型的读取器 ...