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: 看似简单,倘若 ...
随机推荐
- TNS
Oracle中TNS的完整定义:transparence Network Substrate透明网络底层,监听服务是它重要的一部分,不是全部,不要把TNS当作只是监听器 ORACLE当中,如果想访问某 ...
- unity中让摄像机移动到鼠标点击的位置和鼠标控制平移视角
private Vector3 targetVector3; private float movespeed=0.5f; private bool IsOver = true; private Gam ...
- 51nod算法马拉松B
首先将原本字符串hash,注意每一个字母要分开了. 然后并查集判断字符相同,将字符ascll吗乘转化为祖先乘. 然后就可以判断相等的情况. 然后考虑相等的情况. 二分枚举中间点,然后如果左边是不相等并 ...
- Cracking The Coding Interview2.4
删除前面的linklist,使用node来表示链表 // You have two numbers represented by a linked list, where each node cont ...
- doctype和Quirks模式
doctype: 告诉浏览器使用什么模式去渲染页面,可能会影响页面的css渲染和js代码的执行. DTD :为了兼容旧的浏览器渲染方式,将DTD作为参数告诉浏览器使用什么模式渲染页面.始于IE6; 1 ...
- transclude
http://jsfiddle.net/ospatil/A969Z/157/ transclude :true 允许指令内部的dom元素, 保留到 自定义指令的template属性里的含有 ng-t ...
- shell中环境变量
Linux中环境变量包括系统级和用户级,系统级的环境变量是每个登录到系统的用户都要读取的系统变量,而用户级的环境变量则是该用户使用系统时加载的环境变量. 所以管理环境变量的文件也分为系统级和用户级的, ...
- 类的无参方法和Doc注释
一:Java Doc注释: 语法: /** *AccpSchool 类 *@author JadeBird *@version 1.0 2018/5/26 */ Java Doc是前Sun公司提供的一 ...
- C# 曲线控件 曲线绘制 实时曲线 多曲线控件 开发
Prepare 本文将使用一个NuGet公开的组件来实现曲线的显示,包含了多种显示的模式和配置来满足各种不同的应用场景,方便大家进行快速的开发系统. 在Visual Studio 中的NuGet管理器 ...
- Spring REST API
RPC是面向服务的,并关注与行为和动作:而REST是面向资源的,强调描述应用程序的事务的名词.REST将资源的状态以最适合客户端或服务端的形式从服务器端转移到客户端. REST Representat ...