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: 看似简单,倘若 ...
随机推荐
- Spring Batch 批处理框架介绍
前言 在大型的企业应用中,或多或少都会存在大量的任务需要处理,如邮件批量通知所有将要过期的会员,日终更新订单信息等.而在批量处理任务的过程中,又需要注意很多细节,如任务异常.性能瓶颈等等.那么,使用一 ...
- MySql_delete同时删除多表相关联记录
sql delete同时删除多表相关联记录 sqlserver 支持级联更新和删除oracle 只支持级联删除 删除包含主键值的行的操作,该值由其它表的现有行中的外键列引用.在级联删除中,还删除其外键 ...
- 图解vim常用命令
VI 即 Visual Interface,可视化接口,VIM是VI的增强版 (improved),两张图总结vim常用命令. 图片来自 https://www.cnblogs.com/yangjig ...
- MVC使用Gantt Chart实现甘特图,管理事情进度
借助"甘特图",可以直观地了解任务.活动.工作的进度.dhtmlxGantt是一个开源的Javacirpt库,能帮助我们快速创建"甘特图",本篇体验在MVC中的 ...
- 正确理解java编译时,运行时以及构建时这三个概念
Java中的许多对象(一般都是具有父子类关系的父类对象)在运行时都会出现两种类型:编译时类型和运行时类型,例如:Person person = new Student();这行代码将会生成一个pers ...
- 高手写的“iOS 的多核编程和内存管理”
原文地址:http://anxonli.iteye.com/blog/1097777 多核运算 在iOS中concurrency编程的框架就是GCD(Grand Central Dispatch), ...
- HTML5中的Web Storage(sessionStorage||localStorage)理解与简单实例
Web Storage是什么? Web Storage功能,顾名思义,就是在Web上针对client本地储存数据的功能,详细来说Web Storage分为两种: sessionStorage: 将数据 ...
- 优化JDBC编程-多提提意见
优化JDBC编程这是我根据MS SQL SERVER 2000 JDBC DRIVER HELP,并参考其它资料整理而成.ms的这个帮助文件实在有失大家风范,示例代码很.....有兴趣者可以去下载ht ...
- 结合MapReduce和数据集Combining datasets with MapReduce
While in the SQL-world is very easy combining two or more datasets - we just need to use the JOIN ke ...
- C++ 竞赛常用头文件
C.传统 C++ #include <assert.h> 设定插入点 #include <ctype.h> 字符处理 #include <errno.h> 定义错误 ...