The modular modular multiplicative inverse of an integer a modulo m is an integer x such that a-1≡x (mod m). This is equivalent to ax≡1 (mod m). Input There are multiple test cases. The first line of input is an integer T ≍ 2000 indicating the number…
P3811 [模板]乘法逆元 题意 求1-n所有整数在模p意义下的逆元. 分析 逆元 如果x满足\(ax=1(\%p)\)(其中a p是给定的数)那么称\(x\)是在\(%p\)意义下\(a\)的逆元 A 拓展欧几里得算法 \[ax=1(\%p)\] 转换一下也就是 \[ax+py=1\] #include<bits/stdc++.h> using namespace std; typedef long long ll; int extgcd(int a,int b,int&x,int…
P3811 [模板]乘法逆元 给定n,p求1~n中所有整数在模p意义下的乘法逆元. T两个点的费马小定理求法: code: #include <iostream> #include <cstdio> using namespace std; #define int long long int n,mod; inline int read(){ int sum=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='…