ZOJ 3547 The Boss on Mars(容斥)
2015-09-12 00:13
393 查看
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.
in ACM. (1 ≤ n≤ 10^8)
Case2: sum=1+2*2*2*2+3*3*3*3+4*4*4*4=354
分析:难点在于四次方公式。
n*(n+1)*(6*n*n*n+9*n*n+n-1)/30
有了这个我们肯定要算和n不互斥的和,然后减一下就行了
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 employeesin 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=82Case2: sum=1+2*2*2*2+3*3*3*3+4*4*4*4=354
分析:难点在于四次方公式。
n*(n+1)*(6*n*n*n+9*n*n+n-1)/30
有了这个我们肯定要算和n不互斥的和,然后减一下就行了
#include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<string> #include<iostream> #include<queue> #include<cmath> #include<map> #include<stack> #include<set> using namespace std; #define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i ) #define REP( i , n ) for ( int i = 0 ; i < n ; ++ i ) #define CLEAR( a , x ) memset ( a , x , sizeof a ) const int INF=0x3f3f3f3f; typedef long long LL; const int mod=1e9+7; const int p=233333335; int v[10]; //n*(n+1)*(6*n*n*n+9*n*n+n-1)/30 int t,n,m; LL work(LL x) { LL s1=x*(x+1)%mod; LL s2=6LL*x*x%mod*x%mod; LL s3=(9LL*x*x%mod+x-1)%mod; LL s=(s1*((s2+s3)%mod)%mod)*p%mod; return s; } LL Cal(LL x) { LL s=x*x%mod*x%mod*x%mod; LL l=n/x; return s*work(l)%mod; } int main() { scanf("%d",&t); while(t--) { scanf("%d",&n); m=0;int x=n; for(int i=2;i*i<=x;i++) { if(x%i==0) { while(x%i==0) x/=i; v[m++]=i; } } if(x>1) v[m++]=x; LL ans=0; for(int i=1;i<(1<<m);i++) { LL c=0,l=1; for(int j=0;j<m;j++) { if(i&(1<<j)) { c++; l*=v[j]; } } if(c&1) ans=(ans+Cal(l))%mod; else ans=(ans-Cal(l)+mod)%mod; } LL all=work(n); ans=(all+mod-ans)%mod; printf("%lld\n",ans); } return 0; }
相关文章推荐
- yii 1 安装教程
- 这周的《财经郎眼 - 股市到底了吗》非常不错
- myecplice和ecplice远程调试
- Leetcode 227 Basic Calculator II
- html5+css3项目 (企业网站之标题)
- 81. Search in Rotated Sorted Array I II
- [leetcode] 187 Repeated DNA Sequences
- Phalcon Framework的Mvc结构及启动流程(部分源码分析)
- 【求割边】
- 交换排序
- HDU 4407 Sum(容斥)
- Tomcat安装、配置、优化及负载均衡详解
- EditText的drawableleft跟随其Gravity
- 活用maven使web.xml可以用maven变量
- 行列式的理解
- POJ 2773 Happy 2006(二分+容斥)
- Hadoop-eclipse-plugin插件安装
- 《机器学习实战》学习笔记:基于朴素贝叶斯的分类方法
- Yii2框架中一些折磨人的坑
- PHP比C/C++或Java少了什么?多线程,多线程,多线程……