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: 看似简单,倘若 ...
随机推荐
- webpack入门(1)
webpack入门(1) 源码戳这里 ps:每个案例对应相应的demo,例如"案例1"对应"demo1" 一.webpack基本功能及简单案例 安装webpac ...
- Hibernate3 jar包的作用[转]
from:http://nopainnogain.iteye.com/blog/761630 (1)hibernate3.jar: Hibernate的核心库,没有什么可说的,必须使用的jar包 (2 ...
- C++源码里没有./configure文件的问题
使用autoreconf软件来进行生成即可,在命令行输入autoreconf -vi,注意:前提要安装这个软件yum install autoconf.
- HDU 4727 The Number Off of FFF (水题)
The Number Off of FFF Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Windows Azure 系列-- Azure Queue的操作
- Storage Account. 和之前介绍的Azure Table和AzureBlob一样.你须要一个StorageAccount,仅仅须要创建1次AzureStorageAccount就好了, ...
- C# iTextSharp 生成 PDF
使用iTextSharp在Asp.Net中操作PDF系列文章 目录 http://www.cnblogs.com/CareySon/category/332146.html 实战 iTextSharp ...
- GlobalGetAtomName GlobalDeleteAtom 引用 WinAPI: AddAtom、DeleteAtom、FindAtom、GetAtomName、GlobalAddAtom、GlobalDeleteAtom、GlobalFindAtom、GlobalGetAtomName
http://www.cnblogs.com/del/archive/2008/02/28/1085124.html 这是储存字符串的一组 API.通过 AddAtom 储存一个字符串, 返回一个 I ...
- C#实现ATM自动取款机
本篇用C#实现ATM自动取款机的一些功能.面临的第一个问题是:如何把与自动取款机相关的有形的.无形的方面抽象出来.大致如下: (1)关于用户帐号的类:Account(2)关于银行数据库的类:BankD ...
- ubuntu 键盘布局修改
键盘打不出 | 符号 sudo dpkg-reconfigure keyboard-configuration 改为标准的罗技键盘
- struts从2.3.X升级到2.5.18中遇到的问题及解决办法
1,2.5.X版本不再提供xwork.jar ,整合到了 struts-core包中.2,需要升级替换的jar文件:commons-langcommons-lang3ognl其他所有struts2开头 ...