Pagini recente » Cod sursa (job #2967025) | Cod sursa (job #2945247) | Cod sursa (job #3252046) | Profil Corman_Alexandru_Stefan_325CC | Cod sursa (job #1343600)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long rez=1,a,n;
void citire()
{
fin>>a>>n;
}
void putere(long long x,long long n,long long &rez)
{
while(n>0)
{
if(n%2==0)
{x=x*x;
n=n/2;
}
else
{
rez=rez*x;
x=x*x;
n=n/2;
}
}
}
int main()
{
citire();
putere(a,n-2,rez);
fout<<rez%n;
return 0;
}