exgcd求逆元全输出1
查看原帖
exgcd求逆元全输出1
1053122
shy_lihui楼主2025/1/8 20:04
#include<bits/stdc++.h>
using namespace std;
int p,x,y,n;
void exgcd(int a,int b)
{
	if(b==0)
	{
		x=1;
		y=0;
	}
	else
	{
		swap(x,y);
		exgcd(b,a%b);
		y-=a/b*x;
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>p;
	for(int i=1;i<=n;i++)
	{
		x=0;
		y=0;
		exgcd(i,p);
		x=(x%p+p)%p;
		cout<<x<<'\n';
	}
	
	return 0;
}
2025/1/8 20:04
加载中...