http://acm.hdu.edu.cn/showproblem.php?pid=6390

题意:求一个式子

题解:看题解,写代码

第一行就看不出来,后面的sigma公式也不会化简。mobius也不会

就自己写了个容斥搞一下(才能维持现在的生活)

//别人的题解https://blog.csdn.net/luyehao1/article/details/81672837

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include<ctime>
using namespace std;
const int maxn = 1e6 + ;
typedef long long ll;
ll F[maxn], phi[maxn], inv[maxn];
ll N, M, P;
void init(int n) {
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 - );
}
}
}
void init2(void) {
inv[] = ;
for (int i = ; i <= N; ++i)
inv[i] = (P - P / i * inv[P%i] % P) % P;
for (int i = N; i; --i) {
F[i] = 1ll * (N / i)*(M / i);
// if(i == 1) cout<<F[i]<<endl;
for (int j = i + i; j <= N; j += i)
F[i] -= F [j];
}
}
int main() {
int t; cin >> t;
init(maxn-);
while (t--) {
cin >>N>>M>>P;
if (N < M)swap(N, M);
init2();
ll ans = ;
for (ll i = ; i <= N; ++i) {
ans += (ll)i*inv[phi[i]] % P*(F[i] % P) % P;
ans %= P;
}
cout << ans%P << endl;
}
}
/* */

GuGuFishtion(hdu 6390 欧拉函数+莫比乌斯函数)

hdu 6390 欧拉函数+容斥(莫比乌斯函数) GuGuFishtion的更多相关文章

  1. BZOJ2440(容斥+莫比乌斯函数)

    题目本质: 首先有如下结论: 而通过写一写可以发现: 举例来讲,36及其倍数的数,会被1的倍数加一遍,被4的倍数扣一遍,会被9的倍数扣一遍,而为了最终计数为0,需要再加回来一遍,所以在容斥里面是正号. ...

  2. bzoj 2986: Non-Squarefree Numbers【容斥+莫比乌斯函数】

    看到\( 10^10 \)的范围首先想到二分,然后把问题转化为判断\( [1,n] \)内有多少个是某个质数的平方和的数. 所以应该是加上是一个质数的平方的个数减去是两个质数的平方的个数加上是三个质数 ...

  3. 牛客寒假算法训练1 D 欧拉(容斥)

    1 #include<bits/stdc++.h> using namespace std; ; typedef long long ll; int p[maxn],a[maxn]; ll ...

  4. HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. HDU 6053 TrickGCD 莫比乌斯函数/容斥/筛法

    题意:给出n个数$a[i]$,每个数可以变成不大于它的数,现问所有数的gcd大于1的方案数.其中$(n,a[i]<=1e5)$ 思路:鉴于a[i]不大,可以想到枚举gcd的值.考虑一个$gcd( ...

  6. 【二分+容斥+莫比乌斯反演】BZOJ2440 完全平方数

    Description 求第k个没有完全平方因子的数,k<=1e9. Solution 这其实就是要求第k个µ[i](莫比乌斯函数)不为0的数. 然而k太大数组开不下来是吧,于是这么处理. 二分 ...

  7. hdu1695(莫比乌斯)或欧拉函数+容斥

    题意:求1-b和1-d之内各选一个数组成数对.问最大公约数为k的数对有多少个,数对是有序的.(b,d,k<=100000) 解法1: 这个能够简化成1-b/k 和1-d/k 的互质有序数对的个数 ...

  8. hdu 1695 GCD(欧拉函数+容斥)

    Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD( ...

  9. HDU 1695 GCD 欧拉函数+容斥定理

    输入a b c d k求有多少对x y 使得x在a-b区间 y在c-d区间 gcd(x, y) = k 此外a和c一定是1 由于gcd(x, y) == k 将b和d都除以k 题目转化为1到b/k 和 ...

随机推荐

  1. Swift Defer 延迟调用

    1.Defer 在一些语言中,有 try/finally 这样的控制语句,比如 Java.这种语句可以让我们在 finally 代码块中执行必须要执行的代码,不管之前怎样的兴风作浪.在 Swift 2 ...

  2. mysql乱码问题解决办法

    最近开发一下小项目,遇到了最常见的乱码问题. 1.数据库使用utf-8  utf-8_generic_ci编码,使用csv上传并导入数据,插入数据的时候出现了问题,有很大部分数据没有被导入,所以使用m ...

  3. (转-经典-数据段)C++回顾之static用法总结、对象的存储,作用域与生存期

    转自:https://blog.csdn.net/ab198604/article/details/19158697相关知识补充:https://www.cnblogs.com/rednodel/p/ ...

  4. Redis之AOF重写及其实现原理

    Reference: https://blog.csdn.net/hezhiqiang1314/article/details/69396887 AOF 重写AOF 持久化是通过保存被执行的写命令来记 ...

  5. oracle删除数据库中的所有表

    连接:http://linben.blog.51cto.com/6205951/1293619 1.先禁用数据库中所有的约束 select 'alter table ' || table_name | ...

  6. 【Unity】Protobuf的使用与常见问题

    Protobuf的使用流程 protobuf参考教程:https://www.jianshu.com/p/b135676dbe8d 手写.proto文件后,用CMD命令行运行protoc.exe编译器 ...

  7. 解决com.mysql.jdbc.PacketTooBigException: Packet for query is too large

    在做查询数据库操作时,报了以上错误,还有out of memery heap hacp ,原因是MySQL的max_allowed_packet设置过小引起的,我一开始设置的是1M,后来改为了20M ...

  8. java对象与map对象相互转换

    /** * 使用org.apache.commons.beanutils进行转换 */ class A { public static Object mapToObject(Map<String ...

  9. shell脚本介绍
 shell脚本结构和执行
date命令用法
 shell脚本中的变量

  10. Spring 3 Java Based Configuration with @Value

    Springsource has released the Javaconfig Framework as a core component of Spring 3.0. There is a tre ...