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 ...
随机推荐
- python对web服务器做压力测试并做出图形直观显示
压力测试有很多工具啊.apache的,还有jmeter, 还有loadrunner,都比较常用. 其实你自己用python写的,也足够用. 压力测试过程中要统计时间. 比如每秒的并发数,每秒的最大响应 ...
- linux-0.11抠代码-bootsect
//bootfun.s .global asm_message .global asm_memmove .global asm_readsector .global asm_checkLBA .cod ...
- Java EE登陆界面生成随机数防止恶意注册或者登录
package cn.com; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.a ...
- Redis bio
还是一个很小的模块. bio就是background io的意思,既然要background,就要创建线程,创建几个线程呢?有几种类型的io,就创建几个线程.同一种类型的job需要排队,所以存放各自的 ...
- CSS3实现8种Loading效果【第二波】
原文:CSS3实现8种Loading效果[第二波] 今晚吃完饭回宿舍又捣鼓了另外几种Loading效果,老规矩,直接“上菜“…… 注:gif图片动画有些卡顿,非实际效果! PS:若要转载请注明出处,尊 ...
- [置顶] ArcGIS发布最新的 ArcGIS Runtime SDK for Android v10.1.1
因为希望有统一的地图解决方案,就是PC端,移动端的数据一致,看到ArcGIS的最新发布,感兴趣的可以围观. 链接:http://blogs.esri.com/esri/arcgis/2013/09/0 ...
- Ubuntu 14.04LTS Gnome GUI初体验及163更新源配制
Ubuntu 14.04 LTS于前天(2014.4.17)公布, 我今天将我的系统升级到最新, 体验了下最新的UI系统. 我选择了Ubuntu Gnome 的GUI界面.我曾经的系统是12.04lt ...
- Lazy Math Instructor
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3721 Accepted: 1290 Description A m ...
- Android Sip学习(三)Android Voip实现
Android Sip学习(三)Android Voip实现 Android Sip学习(准备知识)SIP 协议完整的呼叫流程 Android Sip学习(一)Android 2.3 APIs S ...
- 绑定运行计划sql_plan_baseline
--因为生产环境运行的sql变化较快,版本号公布比較频繁,造成sql的运行计划不是非常稳定.常常会有一些性能非常查的sql出现 --对于这些sql,我们能够使用sql_plan_baseline对运行 ...