Cod sursa(job #3240549)
Utilizator | Data | 16 august 2024 14:38:02 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream cin("inversmodular.in");
ifstream cout("inversmodular.out");
int a,n,M;
long long pow(long long b, long long exp){
if(exp==0)return 1;
if(exp==1)return b%M;
long long x=pow(b,exp/2);
x=x*x%M;
if(exp&1)x=x*b%M;
return x;
}
long long invmod(long long x)
{
return pow(x,M-2);
}
int main(){
cin>>a>>M;
cout<<invmod(a);
return 0;
}