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. nginx:负载均衡实战(二) keepalived入门

    1.keepalived介绍 顾名思义,keepalived就是保持网络在线的,用来保证集群高可用HA的服务软件.主要防止出现单点故障(坏了一个点导致整个系统架构不可用) 2.详解keepalived ...

  2. C++构造函数和析构函数,以及构造函数特殊成员变量和函数的初始化

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  3. xml文档的读取

    #! /usr/bin/env python3 # -*- coding:utf-8 -*- import xml.dom.minidom  #该模块被用来处理xml文件 #打开xml文档 dom=x ...

  4. cxf http 代码自动生成

    1.下载 cxf 直接进入镜像下载http://mirrors.tuna.tsinghua.edu.cn/apache/cxf/3.1.12/apache-cxf-3.1.12.zip 2.配置 CX ...

  5. centos7安装kvm

    一. 安装kvm前的准备工作 1. 清除iptables规则 service iptables save service iptables stop 2. 关闭selinux sed -i 's/SE ...

  6. <Flume><Source Code><Flume源码阅读笔记>

    Overview source采集的日志首先会传入ChannelProcessor, 在其内首先会通过Interceptors进行过滤加工,然后通过ChannelSelector选择channel. ...

  7. Arduino显示PM2.5

    这代码一般都是复制过来,在小改下就行了 代码如下: #include <Wire.h> #include <LiquidCrystal_I2C.h> #include < ...

  8. JavaWeb:动作标识

    动作标识 一.包含文件标识<jsp:include> 1.介绍 用于向当前页面中包含其他文件.被包含的文件可以是动态文件,也可以是静态文件 2.语法格式 <jsp:include p ...

  9. os与操作系统进行交互,sys解释器相关,random随机数,shutil解压和压缩

    1.os 与操作系统相关 对文件的处理 对路径的处理 import os#主要用于与操作系统进行交互 掌握: print(os.makedirs('a/b/c'))#创建目录 可用递归创建 print ...

  10. 2019-03-20-day015-序列化存储

    昨日回顾 序列化模块: json -- load dump dumps loads pickle -- load dump dumps loads shelve -- 文件 + 字典 f = shel ...