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)为b的逆元
//由费马小定理a^(p-1) = 1(modp) a , p 互质可得
//30的逆元为30^(mod-2)
//由容斥原理非常easy得到与n不互质的数之和为
//对于全部的n的素数因子
//一个素数因子的全部数的四次方之和-有两个素数因子的全部数的四次方之和+有三个。
。。。
//然后用总的减去不互质的即为互质的
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std ;
const int maxn = 1010 ;
typedef __int64 ll ;
const __int64 mod = 1e9+7 ;
int p[maxn] ;
int len ;
ll inv ;
void get_prime(ll n)
{
len = 0 ;
for(int i = 2;i*i <= n;i++)
{
if(n%i == 0)p[++len] = i;
while(n%i==0)n/=i ;
}
if(n>1)p[++len] = n ;
}
ll Pow(ll a , ll b)
{
ll c = 1 ;
while(b)
{
if(b&1)c = (c*a)%mod;
a = (a*a)%mod;
b >>= 1;
}
return c ;
}
ll dfs(int pos , int n)
{
ll ans = 0 ;
for(int i = pos;i <= len ;i++)
{
ll t = n/p[i] ;
ll t_1 = ((((6*Pow(t,5) + 15*Pow(t,4) + 10*Pow(t,3) - t))%mod)*inv)%mod;
ans = (ans + (Pow(p[i] , 4)*(t_1- dfs(i+1 , n/p[i]))))%mod;
}
return ans ;
}
int main()
{
int T ;
scanf("%d" , &T) ;
inv = Pow(30 , mod - 2) ;
while(T--)
{
ll n ;
scanf("%I64d" , &n) ;
get_prime(n) ;
ll ans = (((((6*Pow(n,5) + 15*Pow(n,4) + 10*Pow(n,3) - n))%mod)*inv)%mod - dfs(1 , n))%mod ;
printf("%I64d\n" , (ans+mod)%mod);
}
return 0 ;
}
hdu4059The Boss on Mars 容斥原理的更多相关文章
- 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 容斥原理
On Mars, there is a huge company called ACM (A huge Company on Mars), and it’s owned by a younger bo ...
- 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) ...
- 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) ...
- hdu4059 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: 看似简单,倘若 ...
随机推荐
- Git_集中式vs分布式
创建版本库 时光机穿梭 版本回退 工作区和暂存区 管理修改 撤销修改 删除文件 远程仓库 添加远程库 从远程库克隆 分支管理 创建与合并分支 解决冲突 分支管理策略 Bug分支 Feature分支 多 ...
- bootstrap字体图标不正常显示的原因
本地引入bootstrap.css文件,使用https://v3.bootcss.com/components/站点 字体图标 时不能正常显示,换成 bootstrap 官网的 cdn 链接却能正常显 ...
- SyncThingWin -- Run syncthing as a windows service
SyncThingWin Auto restart and minor bug fixes bloones released this on 23 Dec 2014 There is now an a ...
- XDM、GDM和KDM
XDM.GDM.KDM是三种X Window的显示管理器 (1)XDM(默认的X Window System Display Manager)(2)GDM(gnome提供的Display Manage ...
- oracle-systemtap
https://github.com/hatem-mahmoud/scripts https://mahmoudhatem.wordpress.com/2015/05/26/stapora-v1-0- ...
- FT项目开发技术点(二)
1.mybatis二级缓存,指的的是将数据缓存,而非对象,而非获得的list.缓存将数据库中的数据,是数据,缓存到内存中.之后将数据每次重新加载到list中,所以每次生成的list对象都是不同的,li ...
- 解决eclipse安装maven的问题:Unable to update index for central|http://repo1.maven.org/maven2
问题产生如下:因为单位使用了过滤,访问Internet时,超过10M的内容就拒绝.因为maven插件在初始时,需要下载Maven的index文件,这个文件比较大,有38M多,下载不成功.所以造成使用M ...
- 页面中基于JSTL标签调用函数--之${fn:}内置函数
调用这样一个头文件<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions " ...
- 试用log4jdbc
近日发现一个好东东log4jdbc,他是一个JDBC驱动器,能够记录SQL日志和SQL执行时间等信息.log4jdbc使用SLF4J(Simple Logging Facade For Java)作为 ...
- C++中的public、private、protected成员继承问题
我是C++菜鸟,刚学了一点C++. 先看例子1: /* Item.h */ #include <iostream> #include <string> class It ...