Pagini recente » Statistici Muresan Alex (Fullbuster) | Cod sursa (job #1511370) | Cod sursa (job #1856769) | Cod sursa (job #1510768) | Cod sursa (job #2029677)
#include <stdio.h>
using namespace std;
using i64 = long long;
i64 explog(i64 x,i64 y){
i64 help=1;
while(y>1){
if(y%2==0){
x*=x;
y/=2;
}
else{
help*=x;
x*=x;
y=(y-1)/2;
}
}
return x*help;
}
int main()
{
FILE *in, *out;
in = fopen("inversmodular.in", "r");
out = fopen("inversmodular.out", "w");
i64 a, mod;
fscanf(in, "%lld%lld", &a, &mod);
i64 x=explog(a, mod-2);
fprintf(out, "%lld", x%mod);
return 0;
}