HDU - 4944 FSF’s game
来源:互联网 发布:西科软件招聘 编辑:程序博客网 时间:2024/04/29 20:14
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)
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).
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.
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
313100
Sample Output
Case #1: 1Case #2: 30Case #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 __int64using 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;}
0 0
- HDU - 4944 FSF’s game
- hdu 4944 FSF’s game
- hdu 4944 FSF’s game(数论)
- HDU 4944 FSF’s game 规律题
- 多校hdu FSF’s game 4944
- HDU 4944 FSF’s game(计数游戏)
- HDOJ 4944 FSF’s game
- HDU 4944 FSF’s game 解题报告(递推)
- HDU 4944 FSF’s game(数论+递推)
- hdoj 4944 FSF’s game 【数学思维】
- hdu4944 FSF’s game
- hdu 4944 FSF’s game 数学(公因子)+递推公式
- hdu 4944 FSF’s game 数学(公因子)+递推公式
- hdu FSF’s game 欧拉定理,素数筛法
- HDU4944-FSF’s game(递推)
- HDU4944 FSF’s game【因子和】【递推】
- fsf
- hdu 2147 kiki's game
- spoj 375 Query on a tree(树链剖分模版)
- 设计模式の面向对象
- JSP 页面实现文件上传
- 杨昌英诉张世雄子女抚养及财产分割纠纷案
- 按钮控件
- HDU - 4944 FSF’s game
- Single Round Match
- cocos2dx3.2 学习笔记(3)--ActionsEaseTest(1)
- 贪心算法 摘记
- Android设计模式--适配器模式
- OBEX浅析
- java.lang.NoClassDefFoundError
- git 打patch方法
- TOJ 2861. Divisors