E - GuGuFishtion HDU - 6390 (欧拉函数,反演)
时间:2019-11-18
本文章向大家介绍E - GuGuFishtion HDU - 6390 (欧拉函数,反演),主要包括E - GuGuFishtion HDU - 6390 (欧拉函数,反演)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
Today XianYu is too busy with his homework, but the boring GuGu is still disturbing him!!!!!!
At the break time, an evil idea arises in XianYu's mind.
‘Come on, you xxxxxxx little guy.’
‘I will give you a function ϕ(x)ϕ(x) which counts the positive integers up to xx that are relatively prime to xx.’
‘And now I give you a fishtion, which named GuGu Fishtion, in memory of a great guy named XianYu and a disturbing and pitiful guy GuGu who will be cooked without solving my problem in 5 hours.’
‘The given fishtion is defined as follow:
And now you, the xxxxxxx little guy, have to solve the problem below given mm,nn,pp.’
So SMART and KINDHEARTED you are, so could you please help GuGu to solve this problem?
‘GU GU!’ GuGu thanks.
At the break time, an evil idea arises in XianYu's mind.
‘Come on, you xxxxxxx little guy.’
‘I will give you a function ϕ(x)ϕ(x) which counts the positive integers up to xx that are relatively prime to xx.’
‘And now I give you a fishtion, which named GuGu Fishtion, in memory of a great guy named XianYu and a disturbing and pitiful guy GuGu who will be cooked without solving my problem in 5 hours.’
‘The given fishtion is defined as follow:
Gu(a,b)=ϕ(ab)ϕ(a)ϕ(b)Gu(a,b)=ϕ(ab)ϕ(a)ϕ(b)
And now you, the xxxxxxx little guy, have to solve the problem below given mm,nn,pp.’
(∑a=1m∑b=1nGu(a,b))(modp)(∑a=1m∑b=1nGu(a,b))(modp)
So SMART and KINDHEARTED you are, so could you please help GuGu to solve this problem?
‘GU GU!’ GuGu thanks.
InputInput contains an integer TT indicating the number of cases, followed by TT lines. Each line contains three integers mm,nn,pp as described above.
1≤T≤31≤T≤3
1≤m,n≤1,000,0001≤m,n≤1,000,000
max(m,n)<p≤1,000,000,007max(m,n)<p≤1,000,000,007
And given pp is a prime.
OutputPlease output exactly TT lines and each line contains only one integer representing the answer.
Sample Input
1
5 7 23
Sample Output
2
Solution:
phi(ab) = phi(a)*phi(b)*gcd(a,b)/phi(gcd(a,b))
然后在去枚举gcd就行了
递推逆元爆int?
Code:
#include<bits/stdc++.h> using namespace std; const int maxn = 1e6+100; typedef long long ll; int fac[maxn],mu[maxn],phi[maxn]; int g[maxn]; ll inv[maxn]; void init() { for(int i=1; i<maxn; ++i) fac[i]=i; phi[1]=mu[1]=1; for(int i=2; i<maxn; ++i) { if(fac[i]==i) for(int j=i<<1; j<maxn; j+=i) fac[j]=i; if(i/fac[i]%fac[i]) phi[i]=(fac[i]-1)*phi[i/fac[i]],mu[i]=-mu[i/fac[i]]; else phi[i]=fac[i]*phi[i/fac[i]],mu[i]=0; } } int n,m,p; signed main() { ios::sync_with_stdio(0); init(); int T; cin>>T; while(T--) { cin>>n>>m>>p; int M=min(n,m); for(int i=1; i<=M; i++) { g[i]=0; int MM=min(n/i,m/i); int A=n/i; int B=m/i; for(int d=1; d<=MM; d++) g[i] += 1ll*mu[d]*(n/i/d)*(m/i/d)%p,g[i]%=p; if(g[i]<0) g[i] += p; } int ans=0; inv[1]=1; for( int i=2; i<=M; i++) { inv[i]=1ll*(p-p/i)*inv[p%i]%p; } for(int k=1; k<=M; k++) { ans=(1ll*ans+1ll*k*inv[phi[k]]%p*1ll*g[k]%p)%p; } cout<<ans<<endl; } // 5 1000000 1000000 1000000007 }
原文地址:https://www.cnblogs.com/zhangbuang/p/11881187.html
- Sklearn-train_test_split随机划分训练集和测试集
- 使用shell来定制dbms_sqltune(r7笔记第39天)
- 简单易学的机器学习算法——分类回归树CART
- Java设计模式-状态模式
- DBA和开发同事的一些代沟(四) (r7笔记第36天)
- python获取文件所在目录和文件名,以及检索当前文件名的方法
- 数据同步中的误导(r7笔记第34天)
- java读取xml文件
- 优化算法——粒子群算法(PSO)
- Java开发画板
- Python—numpy模块下函数介绍(一)numpy.ones、empty等
- Tomcat用户权限设置
- 优化算法——模拟退火算法
- 绘制动态心形图案::R语言绘制心形图
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 聊聊dubbo-go的kubernetesRegistry
- QMake复制文件/目录方法
- 计算FPS小例子
- 解读技术 |学习率及其如何改善深度学习算法
- MySQL 5.7 新特性:Generated Column
- 聊聊dubbo-go的nacosRegistry
- 聊聊dubbo-go的PrometheusReporter
- 聊聊dubbo-go的apolloConfiguration
- 聊聊dubbo-go的DefaultHealthChecker
- 一文搞懂matplotlib中的颜色设置
- pyecharts极简入门教程
- Linux gdb+valgrind调试
- matplotlib基础绘图命令之hist
- Python|一文详解数据预处理
- 安排上了!PC人脸识别登录,出乎意料的简单