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)

InputThere 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).OutputOutput 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

HinIn 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

网上题解坑人,本来有点清楚了看了一会还把自己看懵了。重新理顺一下
根据题意写出式子,ans[n]=ans[n-1]+∑ n*i*k/gcd(n,i)

∑ n*i*k/gcd(n,i) //gcd(n,i)/k 为n的因子,
=n∗(1/a1+2/a2+⋯+n/an)  //gcd(n,i)/k =ai,ai为n的因子 也就是说每个n的值对应了n的所有因子的贡献值之和。
比如n=2,因子1,2.
1的贡献  2  4
2的贡献     2
设mi为ai的因子 ∑ n*i*k/gcd(n,i)=n*[(1*m1/m1+2*m1/m1+...n/m1) +(1*m2/m2+2*m2/m2+...n/m2) +........+(1*mn/mn+2*mn/mn+...n/m)] //主要想清楚k/gcd()的值,k的变化对应mi的值
设sum(mi)=(1*mi/mi+2*mi/mi+...n/mi)=(n/m)*(n/m+1)/2
ans[n]=ans[n-1]+sum(mi)*mi

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
typedef long long LL;
#include<algorithm>
using namespace std;
#define N 500005
const LL mod=1LL<<32;
LL ans[N];
LL num[N];
int main()
{
//freopen("i.txt","r",stdin);
//freopen("o.txt","w",stdout);
for(int i=1;i<N;i++)
{
for(LL j=i;j<N;j+=i)
{
num[j]+=(j/i)*(j/i+1)/2;
//cout<<j<<" "<<num[j]<<endl;
}
}
ans[1]=1;
for(LL i=2;i<=500000;i++)
{
ans[i]=ans[i-1]+num[i]*i%mod;
ans[i]%=mod;
//cout<<ans[i]<<endl;
}
int t;
scanf("%d",&t);
for(int l=1;l<=t;l++)
{
int n;
scanf("%d",&n);
cout<<"Case #"<<l<<": "<<ans[n]<<endl; }
}

  

hdu_4944_FSF’s game的更多相关文章

随机推荐

  1. (转)python学习链接

    原文:http://www.cnblogs.com/spykids/category/782491.html http://www.cnblogs.com/alex3714/category/7707 ...

  2. 【计算机网络】一步一步学习IP路由流程

    TCP/IP协议簇是目前互联网应用最广的协议栈,谈到TCP/IP协议栈就不能不讲一讲IP路由的问题,因为在我们使用的网络通信中几乎每时每刻都在发生着IP路由的事件…….当你在网络世界中还是一位新手的时 ...

  3. stm32 窗口看门狗学习(一)

    什么是窗口看门狗? 1)独立看门狗                限制喂狗时间在0-x内,x由相关寄存器决定.喂狗的时间不能过晚. 2)窗口看门狗               之所以称为窗口就是因为其 ...

  4. springCloud 概念介绍

    微服务(Microservice) 那么首先介绍下微服务.微服务英文名称Microservice,Microservice架构模式就是将整个Web应用组织为一系列小的Web服务.这些小的Web服务可以 ...

  5. 使用Zxing生成一维码和二维码

    首先引用zxing.dll 到项目中引用 using System; using System.Collections.Generic; using System.Drawing; using Sys ...

  6. 9种Java单例模式详解

    单例模式的特点 一个类只允许产生一个实例化对象. 单例类构造方法私有化,不允许外部创建对象. 单例类向外提供静态方法,调用方法返回内部创建的实例化对象. 懒汉式(线程不安全) 其主要表现在单例类在外部 ...

  7. java-logic====吃货联盟

    1.系统界面 2.功能一 3.查看餐袋 4.签收订单 5.删除订单 6.我要点赞 主要分在两个类中: 第一个类entity,主要的是一些共有的属性 主要代码: public class entity ...

  8. Android Studio修改默认Activity继承AppCompatActivity(转)

    在Android Studio中新建Activity默认继承AppCompatActivity,感觉这点十分不爽,找了很久,终于发现在Android Studio安装目录下有个模板文件,修改其中的参数 ...

  9. 基于 MUI 构建一个具有 90 +页面的APP应用

    前言 mui是一款接近原生App体验的前端框架,只需要掌握前端技术就可以开发APP应用,官方有提供功能比较全面的demo版本, 但在实战中总会遇到一些不可避免但坑,对于没有接触过mui的开发者,难免会 ...

  10. SublimeText插件vue Syntax Highlight : vue语法高亮

    参考:http://www.cnblogs.com/cosnyang/p/6290950.html Vue.js 的单文件组件(*.vue)在 sublime 编辑器中是不被识别的.若要想高亮显示,需 ...