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.

容斥原理

 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll; const int mod=1e9+; ll QP(ll a,ll n){
ll ans=,tmp=a;
while(n){
if(n&)ans=ans*tmp%mod;
tmp=tmp*tmp%mod;
n>>=;
}
return ans;
} ll getsum(ll n){
return n*(n+)%mod*(*n+)%mod*((n*n*%mod+n*%mod-+mod)%mod)%mod*QP(,mod-)%mod;
} int pnum[],num; int main(){
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
num=;
int tmp=n;
for(int i=;i*(ll)i<=tmp;++i){
if(!(tmp%i)){
pnum[++num]=i;
while(!(tmp%i))tmp/=i;
}
}
if(tmp-)pnum[++num]=tmp;
ll ans=;
for(int i=;i<(<<num);++i){
int bit=;
int mul=;
for(int j=;j<=num;++j){
if(i&(<<(j-))){
bit++;
mul*=pnum[j];
}
}
if(bit%)ans=(ans+QP(mul,)*getsum(n/mul)%mod)%mod;
else ans=(ans-QP(mul,)*getsum(n/mul)%mod)%mod;
}
printf("%lld\n",((getsum(n)-ans)%mod+mod)%mod);
}
return ;
}

hdu4059 The Boss on Mars 容斥原理的更多相关文章

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

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

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

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

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

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

  4. hdu4059 The Boss on Mars

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

  5. hdu4059The Boss on Mars 容斥原理

    //求1到n之间与n互质的数的四次方的和 //segma(n^4) = (6n^5+15n^4+10n^3-n)/30 //对于(a/b)%mod能够转化为(a*inv(b))%mod //inv(b ...

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

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

  7. 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. 数论 + 容斥 - HDU 4059 The Boss on Mars

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

随机推荐

  1. X的平方

    题目描述: 实现 int sqrt(int x) 函数,计算并返回 x 的平方根. 样例 sqrt(3) = 1 sqrt(4) = 2 sqrt(5) = 2 sqrt(10) = 3 题解: 解法 ...

  2. 枚举类返回Map键值对,绑定到下拉框

    有时候,页面的下拉框要显示键值对,但是不想从数据库取,此时我们可以写一个枚举类, Java后台代码 1.枚举类 import java.util.HashMap; import java.util.M ...

  3. DevExpress WinForms使用教程:Ribbon性能

    [DevExpress WinForms v18.2下载] DevExpress XAF团队提供Ribbon新能改进,其中XAF Office Module的实际应用程序需要花费很长时间才能加载,导致 ...

  4. Core Java 面经

    1  面向对象的特征有哪些方面? (1)抽象,抽象就是忽略与当前目标无关的部分,抽象包含两个方面,一是过程抽象,一是数据 (2)继承,是Java中允许和鼓励类重用的思想的体现,, 它提供了一种方式,可 ...

  5. Storm介绍&实际开发注意事项

    一.使用组件的并行度代替线程池 Storm 自身是一个分布式.多线程的框架,对每个Spout 和Bolt,我们都可以设置其并发度:它也支持通过rebalance 命令来动态调整并发度,把负载分摊到多个 ...

  6. Linux文件系统命令 cd

    命令名:cd 功能:切换到某一个目录,后面可以跟相对路径和绝对路径. eg:cd /etc/ 表示的是进入到/etc/目录下 另外几个比较特俗的用法: cd - 切换到当前目录 cd ./ 还是当前路 ...

  7. aapt获取包名和activity,启动app

    1.android sdk的环境安装好了之后,在build-tools\** 的目录下找到aapt.exe,将这个路径设置环境变量,添加到path下 2.在cmdl里面输入:aapt,出现以下内容就是 ...

  8. 关于 数据库 my_slq的 安装及其卸载

    安装的时候 注意事项 自定后 根据电脑的系统版本 选择32  或者64  然后选择→方向键 密码默认是123456  或者  123123 查看装的数据库是否安装好了 如何完全卸载 mysql 数据库 ...

  9. 八、启动linux内核并修改开机logo

    1. 编译并烧写linux内核 1)先准备好内核源码包urbetter-linux2.6.28-v1.0.tgz,输入命令:tar -zxvf urbetter-linux2.6.28-v1.0.tg ...

  10. win7 java环境变量配置

    进行win7下Java环境变量配置      在"系统变量"下进行如下配置: (1)新建->变量名:JAVA_HOME变量值 C:\Program Files\Java\jd ...