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 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 容斥原理的更多相关文章
- hdu4059 The Boss on Mars(差分+容斥原理)
题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设 则 为一阶差分. 二阶差分: n阶差分: 且可推出 性质: 1. ...
- 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 ...
- hdu4059 The Boss on Mars
The Boss on Mars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 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 ...
- HDU 4059 The Boss on Mars(容斥原理)
The Boss on Mars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 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 Problem's Link Mean: 给定一个整数n,求1~n中所有与n互质的数的四次方的和.(1<=n<=1e8) analyse: 看似简单,倘若 ...
随机推荐
- json模块&xml
json模块将数据修改成字符串,方便其他语言进行识别. 只认双引号,不认单引号.使用json.dumps的操作步骤 先将单引号修改成单引号 将变量使用单引号引起来 将数据类型编程json字符串 jso ...
- SQL 常用判断语句
我们在做sql更新时,为防止sql重复执行报错,需要对所需要执行的对象进行判断是否存在: 常用判断脚本如下: 判断视图是否存在 IF object_id('viewname') IS not NULL ...
- 【Oracle安装卸载】oracle卸载
Oracle卸载比较麻烦,不能简单卸载就完成了,有时没有卸载完整,下次安装不能很好的安装: 当然Oracle卸载也没有那么难,只是步骤比较多.Oracle10g还是Oracle11g卸载步骤都是一样的 ...
- learning ddr mode register MR3
- Java中数据类型相互转化
1 将String 转换成int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([String], ...
- selenium(六)Headless Chrome/Firefox--PhantomJS停止支持后,使用无界面模式。
简介: 以前都用PhantomJS来进行无界面模式的自动化测试,或者爬取某些动态页面. 但是最近selenium更新以后,'Selenium support for PhantomJS has bee ...
- sass和scss的区别
页面引入的时候还是引入的css文件 因为sass和scss都是一种css的预处理工具 目的最后都是生成css文件 sass不带{}和:是基于Ruby 写出来的,严格的缩进方式来控制 scss带这两个 ...
- tf多线程读取数据
多线程读取数据的机制 tf中多线程读取数据跟常规的python多线程思路一致,是基于Queue的多线程编程. 主线程读取数据,然后计算,在读数据这部分有两个线程,一个线程读取文件名,生成文件名队列,另 ...
- LSTM-自然语言建模
说到自然语言,我就会想到朴素贝叶斯,贝叶斯核心就是条件概率,而且大多数自然语言处理的思想也就是条件概率. 所以我用预测一个句子出现的概率为例,阐述一下自然语言处理的思想. 处理思想-概率 句子,就是单 ...
- wait_activity
wait_activity(self, activity, timeout, interval=1): android特有的 返回的True 或 False :Agrs: - activity - 需 ...