Cod sursa(job #2029677)

Utilizator whitewolf3131Ursu Laurentiu Cristian whitewolf3131 Data 30 septembrie 2017 12:39:41
Problema Invers modular Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.54 kb
#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;
}