HDU 4059 容斥初步练习
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
const LL Mod=;
const LL Maxn=;
LL Factor[],cnt,n,m,tot,Rev,Kase,Prime[Maxn];
bool vis[Maxn]; inline LL Quick_Pow(LL x,LL y)
{
LL Ret=;
while (true)
{
if (y&) Ret=(Ret*x)%Mod;
x=(x*x)%Mod; y>>=;
if (y==) break;
}
return Ret;
} inline void Make_Prime()
{
memset(vis,false,sizeof(vis));
for (LL i=;i<Maxn;i++)
{
if (!vis[i]) Prime[++tot]=i;
for (LL j=;j<=tot && Prime[j]*i<Maxn;j++)
{
vis[Prime[j]*i]=true;
if (i%Prime[j]==) break;
}
}
} inline LL Calc(LL N)
{
LL Ret=N;
Ret=(Ret*(N+))%Mod;
Ret=(Ret*(*N+))%Mod;
Ret=(Ret*((*N*N+*N-)%Mod))%Mod;
Ret=(Ret*Rev)%Mod;
return Ret;
}
inline void Get_Factor(LL P)
{
cnt=;
for (LL i=;i<=tot && Prime[i]<=P;i++)
if (P%Prime[i]==)
{
Factor[++cnt]=Prime[i];
while (P%Prime[i]==) P/=Prime[i];
}
if (P!=) Factor[++cnt]=P;
}
inline LL Pow2(LL x) {return (x*x)%Mod;}
inline LL Pow4(LL x) {return (Pow2(x)*Pow2(x))%Mod;}
LL Dfs(LL d,LL start)
{
LL Ret=;
for (LL i=start;i<=cnt;i++)
{
LL tmp=Pow4(Factor[i]);
Ret=(Ret+(tmp*Calc(d/Factor[i]))%Mod)%Mod;
Ret=(Ret-(tmp*Dfs(d/Factor[i],i+))%Mod+Mod)%Mod;
}
return Ret;
}
inline LL Solve()
{
Get_Factor(n);
return ((Calc(n)%Mod)-(Dfs(n,))%Mod+Mod)%Mod;
}
int main()
{
scanf("%lld",&Kase);
Rev=Quick_Pow(,Mod-);
Make_Prime(); for (LL kase=;kase<=Kase;kase++)
{
scanf("%lld",&n);
printf("%lld\n",Solve());
}
return ;
}
HDU 4059
求的是与n互质的数的四次方的和。 首先四次方有个公式。把1~n的然后减去n的约数的四次方即可,这就需要用到容斥了。
Sum(2)-(Sum(2*3)+Sum(2*5)+Sum(2*7)..)+(Sum(2*3*5)+Sum(2*3*7)+Sum(3*5*7)..)-..
HDU 4059 容斥初步练习的更多相关文章
- HDU 4135 容斥
问a,b区间内与n互质个数,a,b<=1e15,n<=1e9 n才1e9考虑分解对因子的组合进行容斥,因为19个最小的不同素数乘积即已大于LL了,枚举状态复杂度不会很高.然后差分就好了. ...
- HDU 2841 容斥 或 反演
$n,m <= 1e5$ ,$i<=n$,$j<=m$,求$(i⊥j)$对数 /** @Date : 2017-09-26 23:01:05 * @FileName: HDU 284 ...
- HDU 1695 容斥
又是求gcd=k的题,稍微有点不同的是,(i,j)有偏序关系,直接分块好像会出现问题,还好数据规模很小,直接暴力求就行了. /** @Date : 2017-09-15 18:21:35 * @Fil ...
- hdu 1220 容斥
http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others) Memory ...
- Co-prime HDU - 4135_容斥计数
Code: #include<cstdio> #include<cstring> #include<cmath> #include<iostream> ...
- How many integers can you find HDU - 1796_容斥计数
Code: #include<cstdio> using namespace std; typedef long long ll; const int R=13; ll a[R]; ll ...
- hdu 4059 The Boss on Mars 容斥
题目链接 求出ai^4+a2^4+......an^4的值, ai为小于n并与n互质的数. 用容斥做, 先求出1^4+2^4+n^4的和的通项公式, 显然是一个5次方程, 然后6个方程6个未知数, 我 ...
- 数论 + 容斥 - HDU 4059 The Boss on Mars
The Boss on Mars Problem's Link Mean: 给定一个整数n,求1~n中所有与n互质的数的四次方的和.(1<=n<=1e8) analyse: 看似简单,倘若 ...
- HDU - 4059: The Boss on Mars (容斥 拉格朗日 小小的优化搜索)
pro: T次询问,每次给出N(N<1e8),求所有Σi^4 (i<=N,且gcd(i,N)==1) ; sol: 因为N比较小,我们可以求出素因子,然后容斥. 主要问题就是求1到P的 ...
随机推荐
- less中的减号处理
很奇怪,less中对减号似乎没有特别说明,很容易让人无用. @div1Width:500; @div2Width:200px; .div3cls { width:@div1Width-@div2Wid ...
- SQL Developer报错:Unable to find a Java Virtual Machine解决办法
安装了64位的Oracle数据库以及32位的Oracle客户端,在开始菜单中第一次打开客户端的SQL Developer时提示输入java.exe的路径,我选择了Oracle数据库自带的jdk路径,确 ...
- 苹果下如果安装nginx,给nginx安装markdown第三方插件
用brew install nginx 这样安装的是最新版的nginx, 但是在有些情况下,安装第三方插件需要特定的版本,更高一级的版本可能装不上. 它的原理是下载安装包进行自动安装,建立软链,这样就 ...
- vue新建项目
一直都被如何用vue.js新建一个项目的问题困扰着,经过好久的实践,终于搞清楚如何用vue新建项目了: 1.官网对于vue-cli介绍: Vue.js provides an official CLI ...
- 使用centos引导内核错误:kernel: pnp 00:0b: can't evaluate _CRS: 8
CentOS系统在开机过程中,一直遇到黑屏提示:“kernel: pnp 00:0b: can't evaluate _CRS: 8”,不理会它仍能启动系统并正常工作,未知何故. 经查,这是内核引导的 ...
- [字符哈希] POJ 3094 Quicksum
Quicksum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16488 Accepted: 11453 Descri ...
- C++中的数组
数组名作为参数时,传递的是数组的首地址, 主调函数中实参数组元素个数不应该少于形参数组的元素个数 把数组名作为参数时,一般不指定数组第一维的大小 即使指定,编译时也会被忽略的.
- 第二讲(核心c#)
一.C#类型 .字段和局部变量的作用域冲突 using System; namespace Wrox { public class ScopeTest2 { ; public static void ...
- ScrollView can host only one direct child
Android 采用ScrollView布局时出现异常:ScrollView can host only one direct child. 异常原因: 主要是ScrollView内部只能有一个子元素 ...
- ros科大讯飞语音识别
转自http://www.ncnynl.com/archives/201611/1069.html ROS入门教程-编写科大讯飞语音SDK的ROS包 说明 ROS软件包xfei_asr是集成自科大讯飞 ...