Pagini recente » Profil Rodik_Rody | Cod sursa (job #1528637) | Cod sursa (job #2969336) | Cod sursa (job #1878540) | Cod sursa (job #2711092)
#include <bits/stdc++.h>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
const int N = 100010;
int a,n,putere(int,int),euler(int);
int main()
{
f>>a>>n;
g<<putere(a,euler(n)-1);
return 0;
}
int putere(int b,int e)
{
if(e==0)
return 1;
int r=putere(b,e/2);
r=1LL*r*r%n;
if(e%2==1)
r=1LL*r*b%n;
return r;
}
int euler(int x)
{
int r=1;
if(x%2)
{
x/=2;
while(x%2==0)
{
x/=2;
r*=2;
};
}
for(int d=3; d*d<=x; d+=2)
if(x%d==0)
{
x/=d;
r*=d-1;
while(x%d==0)
{
x/=d;
r*=d;
}
}
if(x>1)
r*=x-1;
return r;
}