Cod sursa(job #2290504)

Utilizator TeodorAxinteAxinte Teodor TeodorAxinte Data 26 noiembrie 2018 16:50:40
Problema Invers modular Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
typedef long long Int;
const Int MOD = 1999999973LL;
inline int produs(Int x,Int y){return x*y%MOD;}
inline int putere(int b,int e)
{
    if(e==0)
        return 1;
    int r=putere(b,e/2);
    r=produs(r,r);
    if(e%2)
        r=produs(r,b);
    return r;
}
Int n,a,m,sol,phi,p,q;
int main()
{
    fin>>a>>n;
    m=n;
    phi=1;
    for(p=2;p*p<=n;p++)
    if(m%p==0)
    {
        m/=p;phi*=p-1;
        while(m%p==0)
        {
            m/=p;
            phi*=p;
        }
    }
    sol=putere(a,phi-1);
    fout<<sol;
    return 0;
}