QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#633992 | #7735. Primitive Root | Yurily# | WA | 1ms | 3636kb | C++20 | 754b | 2024-10-12 16:31:44 | 2024-10-12 16:31:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
long long p,m;
long long calc(long long st,long long ed){
if(ed<st)
return 0;
long long l;
if(st-2<=0)
l=0;
else
l=(st-2)/p;
long long r=(ed-1)/p;
return r-l;
}
void solve(){
cin>>p>>m;
if(m==0){
if(p==2){
cout<<1<<endl;
}
else
cout<<0<<endl;
return;
}
long long ans=0,st=0,ed;
for(int i=62;i>=0;--i){
if((1ll<<i)&m){
if((1ll<<i)&p){
st+=((1ll)<<i);
}
ed=st+((1ll)<<i)-1;
ans+=calc(st,ed);
if((1ll<<i)&p){
st-=((1ll)<<i);
}
else
st+=((1ll)<<i);
}
else{
if((1ll<<i)&p){
st+=((1ll)<<i);
}
}
}
cout<<ans<<endl;
}
int main(){
int T;
cin>>T;
while(T--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3636kb
input:
3 2 0 7 11 1145141 998244353
output:
1 1 871
result:
wrong answer 2nd lines differ - expected: '2', found: '1'