QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#720708 | #7735. Primitive Root | guangxuautumn | WA | 0ms | 3608kb | C++14 | 808b | 2024-11-07 13:45:17 | 2024-11-07 13:45:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve()
{
ll p, m;
cin >> p >> m;
if(m == 0) {
if(p == 2) cout << 1 << endl;
else cout << 0 << endl;
return;
}
//for(int i = 1; i < 1000; i ++) {
// if(((p * i + 1) % p) ^ (p - 1) > (p * i + 1) % p) {
// cout << 1;
// }else cout << 0;
//}
ll ans = 1;
ll maxk = (m - 1) / p;
if(((p * maxk + 1) ^ (p - 1)) > m) {
//cout << maxk << ' ' << ((p * maxk + 1) ^ (p - 1)) << endl;
ans --;
} else {
if(((p * (maxk + 1) + 1) ^ (p - 1)) < m) {
ans ++;
}
}
//for(ll i = maxk + 1; ; i ++) {
// if(((p * i + 1)) ^ (p - 1) > m) break;
// else ans ++;
//}
cout << maxk + ans << endl;
}
int main()
{
int t;
cin >> t;
while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3608kb
input:
3 2 0 7 11 1145141 998244353
output:
1 1 872
result:
wrong answer 2nd lines differ - expected: '2', found: '1'