The Boss on Mars

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1335    Accepted Submission(s): 401

Problem Description
On Mars, there is a huge company called ACM (A huge Company on Mars), and it’s owned by a younger boss.

Due to no moons around Mars, the employees can only get the salaries per-year. There are n employees in ACM, and it’s time for them to get salaries from their boss. All employees are numbered from 1 to n. With the unknown reasons, if the employee’s work number is k, he can get k^4 Mars dollars this year. So the employees working for the ACM are very rich.

Because the number of employees is so large that the boss of ACM must distribute too much money, he wants to fire the people whose work number is co-prime with n next year. Now the boss wants to know how much he will save after the dismissal.

 
Input
The first line contains an integer T indicating the number of test cases. (1 ≤ T ≤ 1000) Each test case, there is only one integer n, indicating the number of employees in ACM. (1 ≤ n ≤ 10^8)

 
Output
For each test case, output an integer indicating the money the boss can save. Because the answer is so large, please module the answer with 1,000,000,007.

 
Sample Input
2
4
5
 
Sample Output
82
354

Hint

Case1: sum=1+3*3*3*3=82
Case2: sum=1+2*2*2*2+3*3*3*3+4*4*4*4=354

 
Author
ZHANG, Chao
 
Source
 
Recommend
lcy
这题,我们比赛都写的差不多了,就是在算的时候由于n的平方,爆掉了,不知道哪里错了,一直卡到了最后!也没发现,唉,可惜了!
首先我们可以得到公式1^4+2^4+3^4+.....+m^4为m*(1+m)*(1+2*m)(3*m*m+3*m-1);然后,用个容斥定理就解决问题了!
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
#define mod 1000000007
__int64 vec[33];
int ans;
__int64 prime[10500],pans;
__int64 re;
__int64 n;
int init()
{
int i;
memset(prime,0,sizeof(prime));
for(i=2;i<=10000;i++)
{
if(!prime[i])
for(int j=i+i;j<10050;j=j+i)
{
prime[j]=1;
}
}
pans=0;
for(i=2;i<=10000;i++)
{
if(!prime[i])
prime[pans++]=i;
}
return 1;
}
__int64 ff(__int64 k)
{
int i,j;
__int64 m=(__int64)(n/k),a[5],b[]={2,3,5};
a[0]=m;a[3]=(1+m),a[1]=(1+2*m),a[2]=(3*m*m+3*m-1);
for(j=0;j<=2;j++)
{
for(i=0;i<4;i++)
{
if(a[i]%b[j]==0)
{
a[i]/=b[j];
break;
}
}
}
return a[2]%mod*a[0]%mod*a[1]%mod*a[3]%mod*k%mod*k%mod*k%mod*k%mod;
}
void dfs(int now,int len,__int64 s )
{
int i;
if(len>=ans)
return;
if(now>=ans)
return;
if(len&1)
{
re+=ff(s);
re%=mod;
if(re<0)
re+=mod;
}
else
{
re-=ff(s);
re%=mod;
if(re<0)
re+=mod;
}
for(i=now+1;i<ans;i++)
{
dfs(i,len+1,s*vec[i]);
}
}
bool isp(__int64 ii,__int64 pri)
{
if(pri==1)
return false;
__int64 m=sqrt((double)pri);
for(__int64 i=ii+1;i<pans&&prime[i]<=m;i++)
{
if(pri%prime[i]==0)
return false;
}
return true;
}
int main()
{
init();
int tcase,i;
scanf("%d",&tcase);
while(tcase--)
{
scanf("%I64d",&n);
ans=0;
__int64 m=(__int64)sqrt((double)n)+1;
__int64 tempn=n;
bool flag=true;
if(isp(-1,n))
flag=false;
else
flag=true;__int64 ii=prime[0];
for(__int64 i1=0;flag&&ii<=tempn&&i1<pans;i1++)
{
ii=prime[i1];
if(tempn%ii==0)
{
vec[ans++]=ii;
while(tempn%ii==0)
{
tempn/=ii;
}
if(isp(i1,tempn))
flag=false;
}
}
if(!flag)
vec[ans++]=tempn;
re=ff(1);
for(i=0;i<ans;i++)
dfs(i,0,vec[i]);
printf("%I64d\n",re);
}
return 0;
}

hdu4059 The Boss on Mars的更多相关文章

  1. hdu4059 The Boss on Mars(差分+容斥原理)

    题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设  则    为一阶差分. 二阶差分: n阶差分:     且可推出    性质: 1. ...

  2. hdu4059 The Boss on Mars 容斥原理

    On Mars, there is a huge company called ACM (A huge Company on Mars), and it’s owned by a younger bo ...

  3. HDU 4059 The Boss on Mars 容斥原理

    The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. HDU 4059 The Boss on Mars(容斥原理 + 四次方求和)

    传送门 The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  5. 数论 + 容斥 - HDU 4059 The Boss on Mars

    The Boss on Mars Problem's Link Mean: 给定一个整数n,求1~n中所有与n互质的数的四次方的和.(1<=n<=1e8) analyse: 看似简单,倘若 ...

  6. The Boss on Mars

    The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. HDU 4059 The Boss on Mars(容斥原理)

    The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. hdu 4059 The Boss on Mars

    The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. zoj 3547 The Boss on Mars

    需要用到概率论的容斥定理以及计算1 ^ 4 + 2 ^ 4 + ……+ n ^ 4的计算公式1^4+2^4+……+n^4=n(n+1)(2n+1)(3n^2+3n-1)/30 #pragma comm ...

随机推荐

  1. php连接oracle及简单操作

    使你的php支持oracle,按照以下步骤即可: 1.安装php环境,找一下appserv或者xampp,一键安装,很方便 2.把php的ext目录下的php_oci8.dll拷到system32目录 ...

  2. Hadoop学习之HBase

    1. HBase有哪些基本的特征? 2. HBase相对于关系数据库能解决的问题是什么? 3. HBase的数据模型是什么?如何表述?有哪些操作形式? 4. HBase的模式Schema设计的一些概念 ...

  3. crm查询记录共享给了哪些人

    有时候,我们须要查询一个记录.共享给了哪些人?怎么做? 第一种做法:是sql的方式 select * from PrincipalObjectAccess where objectid = '5226 ...

  4. 微信jssdk已无力吐槽

    微信强大的整合能力让企业公众号的开发迅速窜红.尤其是企业须要个性化定制的一些功能.公司在同一时候上线的app和触屏版的应用中,微信分享自然是不可或缺的重要一环. 纵观如今大多数的微信公众号.分享大都是 ...

  5. Swift - 实现拨打电话

    要实现打电话功能,最简单最直接的方式便是:直接跳到拨号界面 (注意:这个需要真机调试,模拟器无效果) 1 2 //自动打开拨号页面并自动拨打电话 UIApplication.sharedApplica ...

  6. 图解C#_事件

    概述 今天用来演示事件的例子是模拟实现一个文件下载类,在这个类中我将定义一个DownLoad事件,这个事件用来在文件下载的过程中,向订阅这个事件的用户发出消息,而这个消息将用DownLoadEvent ...

  7. FMX对象释放

    今天盒子中有朋友遇到对象释放的问题,原文在这里,他的实现大意是建立一个TmyLayout = class(TLayout),然后在这个类中画线,Form对象调用实例化这个类来画线,然后释放掉这个对象, ...

  8. 基于visual Studio2013解决C语言竞赛题之1082迷宫

        题目 解决代码及点评 /************************************************************************/ /* ...

  9. 关于如何解决谷歌Chrome浏览器空白页的问题

    谷歌Chrome浏览器突然不打开任何网页,无论是任何站点(如http://www.baidu.com), 还是Chrome浏览器的设置页面(chrome://settings/), 扩展页面 ( ch ...

  10. 【Dev Club 分享】腾讯验证码的十二年

    源:http://mp.weixin.qq.com/s?__biz=MzA3NTYzODYzMg==&mid=2653578147&idx=3&sn=94a8f8f8b4a23 ...