ZOJ 3547 - The Boss on Mars(容斥)
2015-08-10 17:01
260 查看
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 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
24
5
Sample Output
82354
Hint
Case1: sum=1+3*3*3*3=82Case2: sum=1+2*2*2*2+3*3*3*3+4*4*4*4=354
思路:首先对N分解质因子,10^8以内最对8个质因子,然后减去跟N有相同质因子的数,这样减肯定会减重,所以要用容斥
[code]#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<cmath> #include<queue> #include<stack> #include<map> #include<set> #include<algorithm> using namespace std; typedef long long LL; const int maxn=110; const int maxm=1010; const LL MOD=1e9+7; const int INF=0x3f3f3f3f; const int inv30=233333335; int N,cnt; int a[maxn]; bool is_prime(int x) { if(x==1)return false; int k=sqrt(x); for(int i=2;i<=k;i++) if(x%i==0)return false; return true; } void process(int n) { cnt=0; int k=sqrt(n); for(int i=2;i<=k;i++) { if(n==1)break; if(n%i)continue; a[cnt++]=i; while(n%i==0)n/=i; } if(is_prime(n)){a[cnt++]=n;} } LL getsum(LL x) { LL sum=x; sum=(sum*(x+1))%MOD; sum=(sum*(2*x+1))%MOD; sum=((3*x*x%MOD+3*x)%MOD-1+MOD)%MOD*sum%MOD; return sum; } LL cal(LL x) { LL num=N/x; LL sum=getsum(num); sum=(x*x%MOD*x%MOD*x%MOD*sum)%MOD; return sum; } int main() { int T; scanf("%d",&T); while(T--) { scanf("%d",&N); process(N); LL ans=getsum(N); for(int i=0;i<(1<<cnt);i++) { int num=0; LL p=1; for(int j=0;j<cnt;j++) if(i&(1<<j))p*=a[j],num++; if(num==0)continue; if((num&1)==0)(ans+=cal(p))%=MOD; else ans-=cal(p),ans=(ans+MOD)%MOD; } printf("%lld\n",(ans*inv30)%MOD); } return 0; }
相关文章推荐
- PC110103(旅行)(The Trip)
- 关于方法的继承和覆写
- MySql查询不区分大小写解决方案(两种)
- HDU 5273 Dylans loves sequence——BestCoder Round #45(DP or 树状数组)
- CentOS 下安装testlink
- onekey一键备份操作系统出错 error 16:Inconsistent filesystem strycture
- spring使用PropertyPlaceholderConfigurer扩展来满足不同环境的参数配置
- 解决 “VC++ 多线程编程,win32,MFC 例子(转)”在高版本上运行有错误的问题
- HDU1004 统计字符串次数
- VC中CDC与HDC的区别
- ps钢笔工具隐藏的知识。
- ObjectARX创建文字
- 完成端口(Q&A)
- 二叉堆与堆排序
- 油量监控
- 找出字符串中第一个只出现一次的字符
- Dalvik虚拟机总结
- IOS如何使用第三方字体
- Oracle 12C -- 扩展varchar2、nvarchar2、和raw数据类型的大小限制
- android EditText里面的文字个数变化,提示自动取消