#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. php empty,isset,is_null比较(差异与异同)

    php empty,isset,is_null比较(差异与异同)  http://www.cnblogs.com/chengmo/archive/2010/10/18/1854258.html

  2. redis + spring 集成

    1.pom <modelVersion>4.0.0</modelVersion> <groupId>com.x.redis</groupId> < ...

  3. LTE Air interface Channels-----http://www.rfwireless-world.com/Tutorials/LTE-logical-transport-physical-channels.html

    LTE technology works based on three channel types viz. logical channel,transport channel and physica ...

  4. Task

    .net 4.0为我们带来了TPL(Task Parallel Library),其中Task相较ThreadPool线程池使用更简单,而且支持线程的取消,完成和失败通知等交互性操作,而这些是Thre ...

  5. 微信支付之扫码支付开发:我遇到的坑及解决办法(附:Ecshop 微信支付插件)

    前段时间帮一个朋友的基于ecshop开发的商城加入微信扫描支付功能,本以为是很简单的事儿——下载官方sdk或开发帮助文档,按着里面的做就ok了,谁知折腾了两三天的时间才算搞定,中间也带着疑问在网上找了 ...

  6. Leetcode 详解(ReverseWords)

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

  7. 关于jquery中html()、text()、val()的区别

    1. .html()用为读取和修改元素的HTML标签    对应js中的innerHTML .html()是用来读取元素的HTML内容(包括其Html标签),.html()方法使用在多个元素上时,只读 ...

  8. tomcat apache 实现负载平衡的小demo

    软件:1个apache,2个tomcat module包:mod_jk.so(下载地址:http://tomcat.apache.org/download-connectors.cgi) 下载文件解压 ...

  9. C# 怎么才能取到网卡的型号信息呢? 如: 博通 NetLink BCM57781 Gigabit Ethernet

    C# 怎么才能取到网卡的型号信息呢?  如: 博通 NetLink BCM57781 Gigabit Ethernet

  10. Fortran版MPI_barrier出现错误可能情况

    在Fortran中的MPI_开头函数都常有一个整数型的错误变量用以函数返回错误信息.如: call MPI_Barrier(MPI_COMM_WORLD,ierr) 在没有ierr参数时,程序可能会出 ...