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

题意:给你个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的更多相关文章

  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 一道好题

    FSF’s game Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tota ...

  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 4944 逆序数对

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 题意: 给出一个序列,可以相邻的交换k次,求 k 次之后,逆序数对最少是多少: 分析: 可以发现 ...

  5. HDU 4944

    FSF’s game Problem Description FSF has programmed a game.In this game, players need to divide a rect ...

  6. HDOJ 4944 FSF’s game

    http://blog.csdn.net/keshuai19940722/article/details/38519681 不明真相的补一发... FSF's game Time Limit: 900 ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. JavaScript弹出框

    confirm(str); 参数说明: str:在消息对话框中要显示的文本 返回值: Boolean值 返回值: 当用户点击"确定"按钮时,返回true 当用户点击"取消 ...

  2. Git 配置editor编辑器

    Git 配置editor编辑器 在ubuntu系统下,Git默认的编辑器是命令行,学名叫V什么的,使用起来诸多不便 在编辑提交日志的时候,用的比较多. 可以选择unbuntu默认的文档编辑器作为git ...

  3. SilkTest天龙八部系列7-动态对象识别

    在测试web应用时,我们常常需要面对web页面对象变化频繁,并且使用预定义方式识别对象慢的困难.为了解决这些问题,SilkTest引入了dynamic object recognition技术,它使用 ...

  4. Linux看门狗脚本 1.4

    近期项目的看门狗经历了三个版本号. 第一个版本号: 用ps -ef,假设程序挂了就启动 第二个版本号: 程序因为执行时会出现不再监听7901port,所以不能简单推断机器是不是挂了,而是推断此port ...

  5. vs2016 创建 vsto excel 文件项目的一个问题

    新工作需要些一个基于Excel开发一个工具,vs的 vsto 功能很好用,封装了基于开发office 开的一些工具.但是在实际使用时,创建项目总是报错,提示打开excel文件失败.项目是需要创建一个e ...

  6. 基于visual Studio2013解决算法导论之002归并排序

     题目 归并排序 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <malloc.h> #in ...

  7. 基于Andoird 4.2.2的Account Manager源代码分析学习:AccountManagerService系统服务的添加

    从启动说起 Android系统加载时,首先启动init进程,该进程会启动Zygote进程.Zygote进程执行/system/bin/app_process程序.app_process程序在执行中,通 ...

  8. 使用struts2和poi导出excel文档

    poi眼下应该是比較流行的操作excel的工具了.这几天做了个struts2和poi结合使用来实现导出excel的功能.个人认为还是比較有用的.代码阅读起来也非常easy.下来就来分享下我的心得 1  ...

  9. JAVA多态学习3

    这一节我们来学习抽象类 抽象类–深入讨论 抽象类是java中一个比較重要的类. 1.用abstract关键字来修饰一个类时.这个类就是抽象类. 2.用abstract关键字来修饰一个方法时,这种方法就 ...

  10. mysql导入sql文件过大或连接超时的解决的方法

    前段时间出差在现场开发的时候,导入数据库老是出问题.最后发现了一个奇妙sql语句交给实施,仅仅要导入出错就把例如以下语句运行就能够了.至今屡试不爽. set global max_allowed_pa ...