社区讨论

求助exgcd

P3811【模板】模意义下的乘法逆元参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@lwrd2ye8
此快照首次捕获于
2024/05/29 13:04
2 年前
此快照最后确认于
2024/05/29 16:32
2 年前
查看原帖
CPP
#include<iostream>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
int x, y;
void exgcd(int a, int b){
	if(!b){
		x = 1, y = 0;
		return;
	}
	exgcd(b, a%b);
	int t = x;
	x = y, y = t - a/b*y;
}
int main(){
	int n, p;
	cin >> n >> p;
	for(int i = 1; i <= n; i++){
		exgcd(i, n);
		cout << (x%p+p) % p << "\n";
	}
	return 0;
} 

回复

1 条回复,欢迎继续交流。

正在加载回复...