题目大意:

给定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[]的更多相关文章

  1. 中国剩余定理 & 欧拉函数 & 莫比乌斯反演 & 狄利克雷卷积 & 杜教筛

    ssplaysecond的博客(请使用VPN访问): 中国剩余定理: https://ssplaysecond.blogspot.jp/2017/04/blog-post_6.html 欧拉函数: h ...

  2. 51nod 1237 最大公约数之和 V3【欧拉函数||莫比乌斯反演+杜教筛】

    用mu写lcm那道卡常卡成狗(然而最后也没卡过去,于是写一下gcd冷静一下 首先推一下式子 \[ \sum_{i=1}^{n}\sum_{j=1}^{n}gcd(i,j) \] \[ \sum_{i= ...

  3. UVA11426 GCD - Extreme (II) (欧拉函数/莫比乌斯反演)

    UVA11426 GCD - Extreme (II) 题目描述 PDF 输入输出格式 输入格式: 输出格式: 输入输出样例 输入样例#1: 10 100 200000 0 输出样例#1: 67 13 ...

  4. 洛谷P2568 GCD (欧拉函数/莫比乌斯反演)

    P2568 GCD 题目描述 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 输入输出格式 输入格式: 一个整数N 输出格式: 答案 输入输出样例 输入 ...

  5. ACM学习历程—HYSBZ 2818 Gcd(欧拉函数 || 莫比乌斯反演)

    Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sam ...

  6. BZOJ 2818 GCD 【欧拉函数 || 莫比乌斯反演】

    传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=2818 2818: Gcd Time Limit: 10 Sec  Memory Limit ...

  7. bzoj 2818 Gcd(欧拉函数 | 莫比乌斯反演)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2818 [题意] 问(x,y)为质数的有序点对的数目. [思路一] 定义f[i]表示i之 ...

  8. 洛谷 - P3768 - 简单的数学题 - 欧拉函数 - 莫比乌斯反演

    https://www.luogu.org/problemnew/show/P3768 \(F(n)=\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{n}ijgcd(i ...

  9. 【bzoj4804】欧拉心算 莫比乌斯反演+莫比乌斯函数性质+线性筛

    Description 给出一个数字N 求\(\sum_{i=1}^{n}\sum_{j=1}^{n}\varphi(gcd(i,j))\) Input 第一行为一个正整数T,表示数据组数. 接下来T ...

随机推荐

  1. 【react】---redux-actions的基本使用---【巷子】

    一.安装 cnpm install --save redux-actions 二.为什么使用 redux-actions reducer使用switch case语句进行action类型判断,当act ...

  2. 在webpack4 中利用Babel 7取消严格模式方法

    报错信息: Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on stri ...

  3. iView Card 图文组件

    <Card style="width:3.3rem" :dis-hover="false" > <div style="text-a ...

  4. Error(10028):Can't resolve multiple constant drivers for net “ ” at **.v

    两个进程里都有同一个条件判断的话,会产生并行信号冲突的问题. 同一个信号不允许在多个进程中赋值,否则则为多驱动. 进程的并行性决定了多进程不同能对同一个对象进行赋值.

  5. python--函数基础一

    一.函数意义:可读性,复用性强 # def my_len(s): #def 关键词开头,my_len函数名 # i=0 # for k in s: # i+=1 # print(i) # return ...

  6. ReentrantLock的相关方法使用

    获取锁定 void lock():常用获取锁定的方法 void lockInterruptibly():如果当前线程未被中断,则获取锁定:如果当前线程被中断,则出现异常 boolean tryLock ...

  7. css图片文字

    1.浏览器是把 html 和 css 一起下载并执行的,计算机里把两件事情同时做  异步加载.计算机中的同步异步和我们生活中的正好是相反的. 补充: 同步,是所有的操作都做完,才返回给用户结果.即写完 ...

  8. StringUtils的Join函数

    有一天看到同事用了这么个函数,然而我并没有见过,所以查了查,以后说不定用得到. 包路径:org.apache.commons.lang3.StringUtils; 函数名:StringUtils.jo ...

  9. C# 利用发射动态创建泛型类型的对象,泛型类型支持带惨的构造函数

    static class Program { static void Main(string[] args) { var aaa = Create<AAA>("aaa" ...

  10. nodejs 进阶:封装所有对数据库的常用操作

    //这个模块里面封装了所有对数据库的常用操作 var MongoClient = require('mongodb').MongoClient; var settings = require(&quo ...