Cod sursa(job #1176458)

Utilizator iov.lucaIov Luca iov.luca Data 26 aprilie 2014 09:55:11
Problema Invers modular Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include <cstdio>

using namespace std;
long long putere (int x,int n)
{
    if (n==0) return 1;
    if (n==1) return x;
    if (n%2==0) return putere (x*x,n/2);
    else return x*putere (x*x,(n-1)/2);
}
int main()
{
    FILE *f,*g;
   f=fopen("inversmodular.in","r");
    g=fopen("inversmodular.out","w");
    int x,n,p;
    fscanf(f,"%d%d",&x,&n);
    p=n;
    fprintf(g,"%d",(putere(x,p-2))%n);
    return 0;
}