QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#643610 | #7735. Primitive Root | cy325 | WA | 0ms | 3588kb | C++20 | 1.6kb | 2024-10-15 22:18:43 | 2024-10-15 22:18:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int p,m;
cin>>p>>m;
if(p==1){
cout<<m<<endl;
return;
}else if(m==0){
if(((p-1)^(1))<=m){
cout<<1<<endl;
return;
}else{
cout<<0<<endl;
return;
}
}else{
int idx;
bool flag= true;
if(p%2==0){
idx= m / p;
if(m<p-2){
flag=false;
}
}
else {
idx = m / p + 1;
if(m<p){
flag=false;
}
}
int cnt=idx;
if(flag==false)cnt--;
if(((p-1)^(idx*p+1))<=m){
cnt++;
}else{
cnt--;
}
if(((p-1)^((idx-1)*p+1))>m){
cnt--;
}
if(((p-1)^((idx+1)*p+1))<=m){
cnt++;
}
cout<<cnt<<endl;
return;
}
// int i=0;
// int cnt=0;
// int last=p;
// vector<int> a;
// while(1){
// int x=(p-1)^(i*p+1);
//// if(last>m&&x>m)break;
// if(last>m*2024)break;
// if(x<=m) {
// cnt++;a.push_back(x);
// }
// cout<<"idx:"<<i<<" x:"<<x<<" ";
// last=x;
// i++;
// }
// cout<<endl;
// for(int i=0;i<a.size();i++){cout<<a[i]<<" ";}
// cout<<a.size()<<endl;
// cout<<endl;
}
signed main() {
std::ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--)solve();
// solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3588kb
input:
3 2 0 7 11 1145141 998244353
output:
1 2 871
result:
wrong answer 3rd lines differ - expected: '872', found: '871'