QOJ.ac
QOJ
QOJ is currently under a maintenance. It might be unavailable in the following a few hours.
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#923967 | #3063. Faulty Factorial | blhxzjr | AC ✓ | 1493ms | 3712kb | C++23 | 1.3kb | 2025-03-02 13:40:07 | 2025-03-02 13:40:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+ 7;
int qpow(int a,int b,int p = mod) {
int base = a,res = 1;
while (b) {
if (b & 1) {
res = res * base % p;
}
b >>= 1;
base = base * base % p;
}
return res%p;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,p,r;
cin >> n >> p >> r;
// cout << qpow(2,4,1e9 + 7) <<endl;
if(n>=2*p){
if(r==0) cout << 2 << " " << 1 << "\n";
else cout << -1 << " " << -1 << "\n";
}
else if(n<2*p && n>=p){
if(r==0){
if(n==p){
if(n==2) cout << -1 << " " << -1 << "\n";
else cout << p-1 << " " << p-2;
}
else cout << p+1 << " " << p << "\n";
}
else{
int qf=1;
for(int i=1; i<=n; i++){
if(i!=p) qf=(qf*i)%p;
}
int da=1,flag=0;
while(da<p){
if(qf*da%p==r){
flag=1;
break;
}
da++;
}
if(flag) cout << p << " " << da << "\n";
else cout << -1 << " " << -1 << "\n";
}
}
else{
int qf=r;
for(int i=1; i<=n; i++){
qf=((qf)*qpow(i,p-2,p))%p;
// cout << qf << "\n";
}
int wz=-1,zhi=-1;
for(int i=1; i<=n; i++){
if((qf*i)%p<i && (qf*i)%p!=0){
wz=i;
zhi=qf*i%p;
break;
}
}
if(!(zhi==-1 && wz==-1)) cout << wz << " " << zhi << "\n";
else cout << -1 << " " << -1 << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
4 5 1
output:
3 2
result:
ok Correct!
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
4 127 24
output:
-1 -1
result:
ok Correct!
Test #3:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
2 2 0
output:
-1 -1
result:
ok Correct!
Test #4:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 2 1
output:
2 1
result:
ok Correct!
Test #5:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
3 2 0
output:
3 2
result:
ok Correct!
Test #6:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
3 2 1
output:
2 1
result:
ok Correct!
Test #7:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
4 2 0
output:
2 1
result:
ok Correct!
Test #8:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
4 2 1
output:
-1 -1
result:
ok Correct!
Test #9:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
1000000000000000000 2 0
output:
2 1
result:
ok Correct!
Test #10:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1000000000000000000 2 1
output:
-1 -1
result:
ok Correct!
Test #11:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 3 0
output:
-1 -1
result:
ok Correct!
Test #12:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 3 2
output:
-1 -1
result:
ok Correct!
Test #13:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
2 3 1
output:
2 1
result:
ok Correct!
Test #14:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
3 3 0
output:
2 1
result:
ok Correct!
Test #15:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
3 3 2
output:
3 1
result:
ok Correct!
Test #16:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
5 3 0
output:
4 3
result:
ok Correct!
Test #17:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
5 3 1
output:
3 1
result:
ok Correct!
Test #18:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
6 3 0
output:
2 1
result:
ok Correct!
Test #19:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
6 3 1
output:
-1 -1
result:
ok Correct!
Test #20:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1000000000000000000 3 0
output:
2 1
result:
ok Correct!
Test #21:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1000000000000000000 3 2
output:
-1 -1
result:
ok Correct!
Test #22:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 7 0
output:
-1 -1
result:
ok Correct!
Test #23:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 7 4
output:
-1 -1
result:
ok Correct!
Test #24:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
6 7 0
output:
-1 -1
result:
ok Correct!
Test #25:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
6 7 3
output:
2 1
result:
ok Correct!
Test #26:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
7 7 0
output:
6 5
result:
ok Correct!
Test #27:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
7 7 3
output:
7 4
result:
ok Correct!
Test #28:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
7 7 1
output:
7 6
result:
ok Correct!
Test #29:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
13 7 0
output:
8 7
result:
ok Correct!
Test #30:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
13 7 3
output:
7 3
result:
ok Correct!
Test #31:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
14 7 0
output:
2 1
result:
ok Correct!
Test #32:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
14 7 1
output:
-1 -1
result:
ok Correct!
Test #33:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1000000000000000000 7 0
output:
2 1
result:
ok Correct!
Test #34:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1000000000000000000 7 5
output:
-1 -1
result:
ok Correct!
Test #35:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 4937129 0
output:
-1 -1
result:
ok Correct!
Test #36:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 4937129 1249280
output:
-1 -1
result:
ok Correct!
Test #37:
score: 0
Accepted
time: 746ms
memory: 3584kb
input:
4937128 4937129 0
output:
-1 -1
result:
ok Correct!
Test #38:
score: 0
Accepted
time: 734ms
memory: 3584kb
input:
4937128 4937129 4041807
output:
4031 1683
result:
ok Correct!
Test #39:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
4937129 4937129 0
output:
4937128 4937127
result:
ok Correct!
Test #40:
score: 0
Accepted
time: 36ms
memory: 3584kb
input:
4937129 4937129 3844991
output:
4937129 1092138
result:
ok Correct!
Test #41:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
7675468 4937129 0
output:
4937130 4937129
result:
ok Correct!
Test #42:
score: 0
Accepted
time: 52ms
memory: 3584kb
input:
7675468 4937129 3435996
output:
4937129 214360
result:
ok Correct!
Test #43:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
9874257 4937129 0
output:
4937130 4937129
result:
ok Correct!
Test #44:
score: 0
Accepted
time: 79ms
memory: 3584kb
input:
9874257 4937129 4502081
output:
4937129 4502081
result:
ok Correct!
Test #45:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
9874258 4937129 0
output:
2 1
result:
ok Correct!
Test #46:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
9874258 4937129 136077
output:
-1 -1
result:
ok Correct!
Test #47:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1000000000000000000 4937129 0
output:
2 1
result:
ok Correct!
Test #48:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1000000000000000000 4937129 600783
output:
-1 -1
result:
ok Correct!
Test #49:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
2 9999991 0
output:
-1 -1
result:
ok Correct!
Test #50:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 9999991 3547763
output:
-1 -1
result:
ok Correct!
Test #51:
score: 0
Accepted
time: 1493ms
memory: 3456kb
input:
9999990 9999991 0
output:
-1 -1
result:
ok Correct!
Test #52:
score: 0
Accepted
time: 1462ms
memory: 3584kb
input:
9999990 9999991 6305202
output:
3283 3204
result:
ok Correct!
Test #53:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
9999991 9999991 0
output:
9999990 9999989
result:
ok Correct!
Test #54:
score: 0
Accepted
time: 85ms
memory: 3584kb
input:
9999991 9999991 3290391
output:
9999991 6709600
result:
ok Correct!
Test #55:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
15088677 9999991 0
output:
9999992 9999991
result:
ok Correct!
Test #56:
score: 0
Accepted
time: 125ms
memory: 3584kb
input:
15088677 9999991 3238851
output:
9999991 8892695
result:
ok Correct!
Test #57:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
19999981 9999991 0
output:
9999992 9999991
result:
ok Correct!
Test #58:
score: 0
Accepted
time: 136ms
memory: 3712kb
input:
19999981 9999991 1114448
output:
9999991 1114448
result:
ok Correct!
Test #59:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
19999982 9999991 0
output:
2 1
result:
ok Correct!
Test #60:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
19999982 9999991 1468197
output:
-1 -1
result:
ok Correct!
Test #61:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1000000000000000000 9999991 0
output:
2 1
result:
ok Correct!
Test #62:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
1000000000000000000 9999991 5561940
output:
-1 -1
result:
ok Correct!
Test #63:
score: 0
Accepted
time: 409ms
memory: 3456kb
input:
2924166 9732533 6303282
output:
7418 6575
result:
ok Correct!
Test #64:
score: 0
Accepted
time: 418ms
memory: 3584kb
input:
3133068 6687881 5091931
output:
51475 53
result:
ok Correct!
Test #65:
score: 0
Accepted
time: 1131ms
memory: 3584kb
input:
8103430 9897059 6793055
output:
6741 1009
result:
ok Correct!
Test #66:
score: 0
Accepted
time: 846ms
memory: 3584kb
input:
5608852 7464623 4135409
output:
4004 827
result:
ok Correct!
Test #67:
score: 0
Accepted
time: 737ms
memory: 3584kb
input:
5399319 6048071 5880044
output:
4142 2871
result:
ok Correct!
Test #68:
score: 0
Accepted
time: 979ms
memory: 3584kb
input:
7602001 8561963 8429820
output:
10566 763
result:
ok Correct!
Test #69:
score: 0
Accepted
time: 652ms
memory: 3584kb
input:
4168376 7768193 5120738
output:
3271 2855
result:
ok Correct!
Test #70:
score: 0
Accepted
time: 257ms
memory: 3584kb
input:
1712124 3894673 1570469
output:
6665 6648
result:
ok Correct!
Test #71:
score: 0
Accepted
time: 631ms
memory: 3584kb
input:
4658359 6914419 1388646
output:
2768 755
result:
ok Correct!
Test #72:
score: 0
Accepted
time: 237ms
memory: 3584kb
input:
1780103 1889131 641681
output:
3524 2999
result:
ok Correct!
Test #73:
score: 0
Accepted
time: 1491ms
memory: 3584kb
input:
9999978 9999991 7955288
output:
-1 -1
result:
ok Correct!
Test #74:
score: 0
Accepted
time: 1474ms
memory: 3584kb
input:
9999974 9999991 7469222
output:
4999996 1
result:
ok Correct!
Test #75:
score: 0
Accepted
time: 1478ms
memory: 3584kb
input:
9999976 9999991 3692550
output:
4999996 4999995
result:
ok Correct!