乘法逆元(拓展欧几里得)

链接:http://www.51nod.com/Challenge/Problem.html#!#problemId=1256

#include
using namespace std;

void egcd(long long a,long long b,long long &x,long long &y){
	if(b == 0){
		x = 1;
		y = 0;
		return;
	}
	egcd(b,a%b,x,y);
	int tmp = x;
	x = y;
	y = tmp - (a/b)*y;
}

int main(){
	long long m,n,x,y;
	cin>>m>>n;
	egcd(m,n,x,y);
	if(x < 0){
		x += n;
	}
	cout<

 

你可能感兴趣的:(数论,51nod(基础题))