CERC2017 F: Faulty Factorial 简单数论题-LMLPHP

 #include  <iostream>
using namespace std;
#define ll long long
const int N = ;
ll n,p,r;
ll poww(ll a,ll b){
ll ans =1ll;
while(b){
if(b&) ans =ans*a%p;
b>>=;
a=a*a%p;
}
return ans%p;
}
int main()
{
//每次都要注意-1 -1的情况
scanf("%lld%lld%lld",&n,&p,&r);
if(n>=*p){
if(r==){
printf("%lld 1\n",p+);
}
else{
printf("-1 -1\n");
}
}
else if(n>=p){
if(r==){
int flag =;
for(ll i=;i<=n;i++){
if(i!=p)//起初if的{}写错了
{
printf("%lld 1\n",i);
flag =;
break;
}
}
if(!flag)printf("-1 -1\n"); //n=p=2
}
else{
ll ans=1ll;
for(ll i=;i<=n;i++) {
if(i!=p) ans =ans*i%p;
}
int flag =;
for(ll i=;i<p;i++){
if(ans*i%p==r) {
printf("%lld %lld\n",p,i);
flag =;
break;
}
}
if(flag==) printf("-1 -1\n");
}
}
else{
ll ans =1ll;
for(ll i=;i<=n;i++) ans =ans*i%p;
int flag =;
ans = poww(ans,p-);//放到里面会超时
for(ll i=;i<=n;i++){
ll x= r*i%p*ans%p;
// ans/i*x%p==r
// x=r*i%p/ans%p;
if(x>=&&x<i){
printf("%lld %lld\n",i,x);
flag =;
break;
}
}
if(!flag) printf("-1 -1\n");
}
return ; }
05-26 11:52