Pagini recente » Cod sursa (job #1281163) | Cod sursa (job #1620200) | Cod sursa (job #1164613) | Cod sursa (job #1160082) | Cod sursa (job #1895819)
#include <fstream>
#include <math.h>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
unsigned long long a,b,nr=1,copie;
unsigned long i;
int main()
{
f>>a>>b;
int ok=1;
copie=b;
for(int k=2;k<=sqrt(b)&&ok;k++)
if(b%k==0) ok=0;
b--;
if(ok) b--;
while(b)
{
if(b&1)
{
nr*=a;
}
a*=a;
b>>=1;
}
g<<nr%copie;
return 0;
}