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: 看似简单,倘若 ...
随机推荐
- empireCMS 帝国cms功能总结
上1 系统 对应左菜单为 系统设置 系统参数设置 基本属性 站点名称,网站地址,关键字,简介,首页模式,php时间, 前台功能,操作时间,来源地址,验证码 用户属性 后台验证码开启,次数限制,时间限制 ...
- HDU 4708 Rotation Lock Puzzle (简单题)
Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 给Android组件添加事件一个很好用的方法
在这里想和大家分享一下很好用的添加事件方法,特别是在处理ListView里的Item事件的时候,很方便. 首先,在XML里布局的时候,添加这样一个属性: android:onClick="C ...
- Vue 组件 data为什么是函数?
在创建或注册模板的时候,传入一个data属性作为用来绑定的数据.但是在组件中,data必须是一个函数,而不能直接把一个对象赋值给它. Vue.component('my-component', { t ...
- ExtJS创建选项卡
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 【maven】排除maven中jar包依赖的解决过程 例子:spring cloud启动zipkin,报错maven依赖jar包冲突 Class path contains multiple SLF4J bindings.
一直对于maven中解决jar包依赖问题的解决方法纠结不清: 下面这个例子可以说明一个很简单的解决方法: 项目启动报错: Connected to the target VM, address: '1 ...
- DevExpress 利用DateEdit 仅显示和选择年份 z
DevExpress只提供了选择月份的控件MonthEdit,并没提供选择选择年份的控件,目测是官方偷懒不想弄,因为要实现的方法也很简单,利用ComboBoxEdit添加年份数据即可,直接封装一个控件 ...
- Selenium2+python自动化46-js解决click失效问题
前言 有时候元素明明已经找到了,运行也没报错,点击后页面没任何反应.这种问题遇到了,是比较头疼的,因为没任何报错,只是click事件失效了. 本篇用2种方法解决这种诡异的点击事件失效问题 一.遇到的问 ...
- 使用 NSPropertyListSerialization 持久化字典与数组
NSPropertyListSerialization The NSPropertyListSerialization class provides methods that convert prop ...
- dtree实现动态加载树形菜单,动态插入树形菜单
1.导入 dtree文件 dtree.css img文件夹 dtree.js 2. 建立对应 的数据库 1 父ID name id 3 建立连接 ...