这种裸题 就是Rho的直接应用
长点记性啊,linux下RAND_MAX=2^31 狂T啊啊
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> abcd;
inline char nc()
{
static char buf[100000],*p1=buf,*p2=buf;
if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
return *p1++;
}
inline void read(ll &x)
{
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
inline ll Random(ll n)
{
// return (ll)((double)rand()/(RAND_MAX+1)*n);
return (ll)rand()*rand()%n;
}
inline ll gcd(ll a,ll b)
{
return b!=0?gcd(b,a%b):a;
}
inline ll Mul(ll a,ll b,ll p)
{
ll t=0;
a%=p; b%=p;
for(;b;b>>=1,a=(a+a)%p)
if(b&1)
(t+=a)%=p;
return t;
}
inline ll Pow(ll a,ll b,ll p)
{
ll t=1;
for(;b;b>>=1,a=Mul(a,a,p))
if(b&1)
t=Mul(t,a,p);
return t;
}
ll rho(ll n,ll c)
{
ll k=2,x=Random(n),y=x,p=1;
for(ll i=1;1;i++)
{
x=(Mul(x,x,n)+c)%n;
if (y==x) return n;
p=gcd(n,abs(x-y));
if(1<p && p<n) return p;
if(i==k) y=x,k<<=1;
}
}
ll e,N,c,r,d,m;
ll P,Q;
inline void Calc(ll n,ll c)
{
ll t=n;
ll k=c;
while(t==n) t=rho(t,k--);
P=t; Q=n/t;
}
inline abcd EXGCD(ll x,ll y){
abcd ret;
if (x<y) { ret=EXGCD(y,x); return abcd(ret.second,ret.first); }
if (y==0) return abcd(1,0);
ret=EXGCD(y,x%y);
return abcd(ret.second,ret.first-x/y*ret.second);
}
inline ll inv(ll a,ll p){
return ((EXGCD(a,p).first)%p+p)%p;
}
int main()
{
srand(10007);
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
read(e); read(N); read(c);
Calc(N,10007);
r=(P-1)*(Q-1);
d=inv(e,r);
m=Pow(c,d,N);
printf("%lld %lld\n",d,m);
return 0;
}