hdu6390 /// 欧拉函数+莫比乌斯反演 筛inv[] phi[] mu[]
题目大意:
给定m n p 求下式


题解:https://blog.csdn.net/codeswarrior/article/details/81700226
莫比乌斯讲解:https://www.cnblogs.com/peng-ym/p/8647856.html
莫比乌斯的mu[]:https://www.cnblogs.com/cjyyb/p/7953803.html
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define mem(i,j) memset(i,j,sizeof(i))
const int N=1e6+; LL mu[N], phi[N];
LL inv[N]; int n,m,p; void initinv() {
inv[]=;
for(int i=;i<N;i++)
inv[i]=inv[p%i]*(LL)(p-p/i)%p;
} // 逆元
void init() {
for(int i=;i<N;i++) phi[i]=i;
for(int i=;i<N;i++)
if(i==phi[i]) {
for(int j=i;j<N;j+=i)
phi[j]=phi[j]/i*(i-);
}
mem(mu,); mu[]=;
for(int i=;i<N;i++)
for(int j=i*;j<N;j+=i)
mu[j]-=mu[i];
} // 欧拉 莫比乌斯 LL moblus(int a,int b,int g) {
LL res=; a/=g,b/=g;
/// gcd(1~a,1~b)=g -> gcd(1~a/g,1~b/g)=1
for(int i=;i<=min(a,b);i++)
res+=(LL)mu[i]*(a/i)*(b/i);
/// mu[i] * (1~a,1~b)中[gcd=g或g的倍数]的数量
return res;
} int main()
{
init();
int t; scanf("%d",&t);
while(t--) {
scanf("%d%d%d",&m,&n,&p);
LL ans=; initinv();
for(int i=;i<=min(m,n);i++) {
LL uF=moblus(n,m,i)%p;
ans=(ans+uF*i%p*inv[phi[i]]%p)%p;
}
printf("%lld\n",ans);
} return ;
}
hdu6390 /// 欧拉函数+莫比乌斯反演 筛inv[] phi[] mu[]的更多相关文章
- 中国剩余定理 & 欧拉函数 & 莫比乌斯反演 & 狄利克雷卷积 & 杜教筛
ssplaysecond的博客(请使用VPN访问): 中国剩余定理: https://ssplaysecond.blogspot.jp/2017/04/blog-post_6.html 欧拉函数: h ...
- 51nod 1237 最大公约数之和 V3【欧拉函数||莫比乌斯反演+杜教筛】
用mu写lcm那道卡常卡成狗(然而最后也没卡过去,于是写一下gcd冷静一下 首先推一下式子 \[ \sum_{i=1}^{n}\sum_{j=1}^{n}gcd(i,j) \] \[ \sum_{i= ...
- UVA11426 GCD - Extreme (II) (欧拉函数/莫比乌斯反演)
UVA11426 GCD - Extreme (II) 题目描述 PDF 输入输出格式 输入格式: 输出格式: 输入输出样例 输入样例#1: 10 100 200000 0 输出样例#1: 67 13 ...
- 洛谷P2568 GCD (欧拉函数/莫比乌斯反演)
P2568 GCD 题目描述 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 输入输出格式 输入格式: 一个整数N 输出格式: 答案 输入输出样例 输入 ...
- ACM学习历程—HYSBZ 2818 Gcd(欧拉函数 || 莫比乌斯反演)
Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sam ...
- BZOJ 2818 GCD 【欧拉函数 || 莫比乌斯反演】
传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=2818 2818: Gcd Time Limit: 10 Sec Memory Limit ...
- bzoj 2818 Gcd(欧拉函数 | 莫比乌斯反演)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2818 [题意] 问(x,y)为质数的有序点对的数目. [思路一] 定义f[i]表示i之 ...
- 洛谷 - P3768 - 简单的数学题 - 欧拉函数 - 莫比乌斯反演
https://www.luogu.org/problemnew/show/P3768 \(F(n)=\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{n}ijgcd(i ...
- 【bzoj4804】欧拉心算 莫比乌斯反演+莫比乌斯函数性质+线性筛
Description 给出一个数字N 求\(\sum_{i=1}^{n}\sum_{j=1}^{n}\varphi(gcd(i,j))\) Input 第一行为一个正整数T,表示数据组数. 接下来T ...
随机推荐
- Rust <0>:源代码组织,Cargo 入门
Rust 源代码组织,使用配套的 Cargo 工具,其功能强大,程序员可摆脱 C/C++ 中需要自行维护 make.cmake 之类配置的工作量. 初始化一个项目: cargo new --bin h ...
- docker volume持久化存储与数据分享
第一种 指定volume文件mysql存储,存储的位置为/var/lib/mysql -v mysql:/var/lib/mysql 第二种 同步文件,将容器中的skeleton文件夹的内容同步到宿主 ...
- strtotime 获取当月最后一天的日期
strtotime('last day of this month', $timestamp);
- RedisTemplate序列号自增id(当前日期+序列号)
话不多上,直接上码 public class TestService { @Resource RedisTemplate<String, Object> redisTemplate; pu ...
- Python之删除字符串中不需要的字符
简单的 str="---你好=====" print(str.strip("-=")) # 你好 从文件中读取多行数据,可以用生成器表达式 with open( ...
- svnversion - 为工作代码产生一个紧缩的 (compat) 版本号
SYNOPSIS 总览 svnversion wc_path [trail_url] OVERVIEW 概述 Subversion 是一个版本控制系统,允许保存旧版本的文件和目录 (通常是源代码),保 ...
- k8s容器-运维管理篇
二. 运维和管理 维护参考网址 https://jimmysong.io/kubernetes-handbook/practice/install-kubernetes-on-centos.html ...
- CSS文字超出省略
.ellipsis { white-space:nowrap overflow:hidden text-overflow:ellipsis }
- vue之路由导航守卫-全局前置守卫
一.使用方式 全局前置守卫用于在路由配置生效之前进行一些动作,可以使用 router.beforeEach 注册一个全局前置守卫: const router = new VueRouter({ ... ...
- leetcode-13双周赛-1256-加密数字
题目描述:编码 方法一: class Solution(object): def encode(self, n): if n == 0: return "" n -= 1 A = ...