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

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
 
 
题意:略。
思路:对于A*B/gcd(A/k,B/k) 看成 N*x/a ,其中x未知,N已知,a是N的因子。
   (因为a必然是N的因子)
        1.现在我们这样转化后,就开始一个一个枚举a了。(我们把a看成了gcd()的整体来看。)
        2.对于一个确定的a值,假设为ai,那么我们现在要做的就是找出 (N*x/a )满足要求的x来。
          并对它进行求和sum(xi/a)*N;(因为N始终没有变化呀。)
          此时 a = gcd(N/k,x/k) 可以转化成  gcd(N,x) = k*a, 
          那么,对于x的取值范围我们知道,是[1,N],求gcd(N,x)=k*a (k是>0的正整数)
          其实就是在[1,N]里,a的倍数,a , 2a , 3a ,4a,,,,,N/a*a , 正确吗?
          会不会遗漏,gcd()=k*a,就是代表最大公约数是a的倍数。
    这样的话,我们就对x进行求和了。sum = a(1+2...N/a) = a*(1+N/a)*N/a/2 =>(1+N/a)*N/2;
         最后根据式子A*x/a,那么就变成  (1+N/a)*N/a /2 * N;
       筛选,dp即可。
 #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 一道好题的更多相关文章

  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

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

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

  4. HDU 2096 小明A+B --- 水题

    HDU 2096 /* HDU 2096 小明A+B --- 水题 */ #include <cstdio> int main() { #ifdef _LOCAL freopen(&quo ...

  5. HDU 1248 寒冰王座(全然背包:入门题)

    HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...

  6. hdu 5071(2014鞍山现场赛B题,大模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 思路:模拟题,没啥可说的,移动的时候需要注意top的变化. #include <iostr ...

  7. hdu 1251 统计难题 (字典树入门题)

    /******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...

  8. HDU 2577 How to Type(dp题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2577 解题报告:有一个长度在100以内的字符串,并且这个字符串只有大写和小写字母组成,现在要把这些字符 ...

  9. [HDU 2602]Bone Collector ( 0-1背包水题 )

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 水题啊水题 还给我WA了好多次 因为我在j<w[i]的时候状态没有下传.. #includ ...

随机推荐

  1. Hibernate的性能优化问题笔记

    性能优化 1.注意session.clear()的运用.尤其是不断分页循环的情况下. a)在一个大集合中进行遍历,遍历取出数据或者对象 b)java会引起内存泄漏吗?在语法上是不可能出现内存泄露的,因 ...

  2. matlab中使用fuzzy工具箱

    4步教你学会使用matlab模糊控制工具箱 Matlab模糊控制工具箱为模糊控制器的设计提供了一种非常便捷的途径,通过它我们不需要进行复杂的模糊化.模糊推理及反模糊化运算,只需要设定相应参数,就可以很 ...

  3. eclipse 导入web项目后,线程假死

    eclipse 导入web项目后,就出现关闭后,线程还存在的情况.使用java mission control 查看发现java script indexing线程在running. 关闭js验证后, ...

  4. 在PHP与HTML混合输入的页面或者模板中就需要对PHP代码进行闭合

    PHP程序的时候会在文件的最后加上一个闭合标签,如下: <?phpclass MyClass{public function test(){//do something, etc.}}?> ...

  5. 在 Django 模板中遍历复杂数据结构的关键是句点字符

    在 Django 模板中遍历复杂数据结构的关键是句点字符 ( . ). 实例二 mysit/templates/myhtml2.html修改如下 <!DOCTYPE html> <h ...

  6. c++之map

    题目描述:     哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔咒,所以他需要你的帮 ...

  7. Oracle的自动统计信息不收集直方图的信息

    Oracle的自动统计信息不收集直方图的信息 在oracle9i中,默认的统计信息收集是不收集直方图信息的,也就是说默认的MOTHOD_OPT模式为FOR ALL COLUMNS SIZE 1 在10 ...

  8. 10与元素亲密接触:盒元素(the box model)

    line-height属性可以设置文本的行间距,可以用像素.em或百分比等于字体大小有关的值定义行间距line-height: 1.6em;(行间距为字体大小的1.6倍) CSS把每一个单一的元素看作 ...

  9. java FileLock

    import java.nio.ByteBuffer; import java.nio.IntBuffer; import java.nio.channels.FileChannel; import ...

  10. 如何用ajax提交多组同样的数据(数组)到后台?

    我在AJAX中这样写 $("#subbutton").click(function(){          var machineCode_1=$("#machineCo ...