Cod sursa(job #1176466)
Utilizator | Data | 26 aprilie 2014 10:03:00 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <iostream>
#include<fstream>
using namespace std;
int s;
long long power (long long x, int n )
{
if(n==0) return 1;
if(n==1)return x%s;
if(n%2==0) return power((x*x)%s,n/2)%s;
else x%s*power((x*x)%s,(n-1)/2)%s;
}
int main()
{
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int x, n;
f>>x>>n;
s=n;
g<<power(x,n-2);
return 0;
}