#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 容斥初步练习的更多相关文章

  1. HDU 4135 容斥

    问a,b区间内与n互质个数,a,b<=1e15,n<=1e9 n才1e9考虑分解对因子的组合进行容斥,因为19个最小的不同素数乘积即已大于LL了,枚举状态复杂度不会很高.然后差分就好了. ...

  2. HDU 2841 容斥 或 反演

    $n,m <= 1e5$ ,$i<=n$,$j<=m$,求$(i⊥j)$对数 /** @Date : 2017-09-26 23:01:05 * @FileName: HDU 284 ...

  3. HDU 1695 容斥

    又是求gcd=k的题,稍微有点不同的是,(i,j)有偏序关系,直接分块好像会出现问题,还好数据规模很小,直接暴力求就行了. /** @Date : 2017-09-15 18:21:35 * @Fil ...

  4. hdu 1220 容斥

    http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  5. Co-prime HDU - 4135_容斥计数

    Code: #include<cstdio> #include<cstring> #include<cmath> #include<iostream> ...

  6. 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 ...

  7. hdu 4059 The Boss on Mars 容斥

    题目链接 求出ai^4+a2^4+......an^4的值, ai为小于n并与n互质的数. 用容斥做, 先求出1^4+2^4+n^4的和的通项公式, 显然是一个5次方程, 然后6个方程6个未知数, 我 ...

  8. 数论 + 容斥 - HDU 4059 The Boss on Mars

    The Boss on Mars Problem's Link Mean: 给定一个整数n,求1~n中所有与n互质的数的四次方的和.(1<=n<=1e8) analyse: 看似简单,倘若 ...

  9. HDU - 4059: The Boss on Mars (容斥 拉格朗日 小小的优化搜索)

    pro: T次询问,每次给出N(N<1e8),求所有Σi^4 (i<=N,且gcd(i,N)==1) ; sol:  因为N比较小,我们可以求出素因子,然后容斥.  主要问题就是求1到P的 ...

随机推荐

  1. Leetcode 详解(ReverseWords)

    Leetcode里面关于字符串的一些问题,描述如下: Given an input string, reverse the string word by word. For example,Given ...

  2. ubuntu下安装python各类运维用模块(以后补充用途)

    环境:ubuntu 16.04LTS,python3,python2 已安装:pip3,pip2 注:基于Python自动化运维这本书上介绍的各模块而来 1.python-rrdtool(just f ...

  3. 第二讲(核心c#)

    一.C#类型 .字段和局部变量的作用域冲突 using System; namespace Wrox { public class ScopeTest2 { ; public static void ...

  4. Windows Server 2012 中80端口被PID为4的系统进程占用解决方法

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP 把"start" 的值改成4.

  5. k8s volume

        只有nfs和rbd的,本人翻译确实很渣         在容器中磁盘文件寿命是短暂的,当在容器中运行一些重要程序时,这会产生一些问题. 首先,当一个容器崩溃后,kubelet将重新启动该容器, ...

  6. android学习之EdieText组件的使用

    界面如下 移通152余继彪 该界面由四个EditText组件和Button按钮还有一个通知Toast完成,首先在xml文件中添加了四个组件和一个按钮还有一个文字显示框,java代码部分为button添 ...

  7. HDU 1222

    题意: 一头狼和一头兔子在一座山中,给你一个数n表示洞的个数,编号从0~n-1.兔子可以随意躲在其中一个洞中,狼每次都从编号为0的洞出发,接下来走到第m个洞中,问兔子能不能活下来,即不被狼吃掉.例如: ...

  8. .net 读取Excel文件报错

    错误内容 Microsoft Office Excel 不能访问文件“D:\WWWRoot\Website\Test\Excels\Test1.xls”. 可能的原因有: 1 文件名称或路径不存在. ...

  9. elasticsearch相关文章

    http://blog.csdn.net/laigood12345/article/category/1113868

  10. IOS setValue forKey

    NSObjiect *obj:[obj setValue:value forKey:@"cpname"]复制代码的时候都会出现这个异常this class is not key v ...