hdu4059 The Boss on Mars
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
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.
4
5
354
Case1: sum=1+3*3*3*3=82
Case2: sum=1+2*2*2*2+3*3*3*3+4*4*4*4=354
#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的更多相关文章
- hdu4059 The Boss on Mars(差分+容斥原理)
题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设 则 为一阶差分. 二阶差分: n阶差分: 且可推出 性质: 1. ...
- 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 ...
- HDU 4059 The Boss on Mars 容斥原理
The Boss on Mars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4059 The Boss on Mars(容斥原理 + 四次方求和)
传送门 The Boss on Mars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 数论 + 容斥 - HDU 4059 The Boss on Mars
The Boss on Mars Problem's Link Mean: 给定一个整数n,求1~n中所有与n互质的数的四次方的和.(1<=n<=1e8) analyse: 看似简单,倘若 ...
- The Boss on Mars
The Boss on Mars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4059 The Boss on Mars(容斥原理)
The Boss on Mars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4059 The Boss on Mars
The Boss on Mars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 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 ...
随机推荐
- 6个最佳的开源Python应用服务器
6个最佳的开源Python应用服务器 首先,你知道什么是应用服务器吗?应用服务器通常被描述为是存在于服务器中心架构中间层的一个软件框架. AD: 首先,你知道什么是应用服务器吗?应用服务器通常被描述为 ...
- C# c++ 传递函数指针
C#和c++之间相互传递函数指针 在C++和C#之中都有很多callback method,可以相互调用吗,怎么传递,是我表弟的问题. 1.定义c++ dll ,导出方法 // sort.cpp : ...
- CentOS 配置 ssh
默认安装ssh是有的.只是hosts访问问题. 1.在hosts.deny文件尾添加sshd:ALL意思是拒绝所有访问请求 [root@localhost ~]# vi /etc/hosts.de ...
- jquery 获取 TABLE单元格的值
1.JQ部分: var tds = $("#table1 td"); tds.click(function(){ //给所有td添加点击事件 var tdSeq = ...
- Java与C#的语法区别(不断更新中...)
1.static关键字: 在java中静态成员能够被对象和类名调用: 在C#中,静态成员只能被类调用不能被对象调用. 2.for循环: 在java中可以在for前面添加标记,然后在for循环中可以br ...
- Windows Azure 安全最佳实践 - 第 3 部分:确定安全框架
构建云应用程序时,安全始终是计划和执行Windows Azure的首要核心因素.第 1 部分提出安全是一项共同责任,Windows Azure为您的应用程序提供超出内部部署应用程序需求的强大安全功能. ...
- sharepoint 2010 在自定义列表的字段上增加功能菜单
sharepoint 2010 在自定义列表的字段上增加功能菜单方法 打开sharepoint designer 2010,找到需要修改的视图页面,例如allitem.aspx,编辑这个页面,点击高级 ...
- Mac Eclipse+Maven+TestNg+ReportNg 生成测试报告
TestNG 是java 的单元测试框架,功能很强大,很方便,但是自动生成的测试报告有待改善,可以使用TestNg 自带的TestNG_xslt更改TestNG报告的样式,这里主要讲解ReportNg ...
- 遇到Audio/Speech相关问题,如何抓取log
[DESCRIPTION] 遇到Audio/Speech相关问题时,经常需要抓取相关log信息,总结抓取方法如下 [SOLUTION] 1. 通话声音相关的问题: Case 1: 通话中某一 ...
- 今天就这么乱糟糟的过啦~刚刚接触html,就稍微写了一下,明天加油,今天直接贴图
2015-01-01 <!DOCTYPE HTML> <html> <head> <meta charset = "gb2312"> ...