QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#672225 | #7735. Primitive Root | wangxiaorui# | WA | 43ms | 3664kb | C++14 | 1.3kb | 2024-10-24 16:03:59 | 2024-10-24 16:04:00 |
Judging History
answer
#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
ll p,m,M;
ll ans;
int n,k;
int idxp[105],idxm[105];
ll pw[105];
void solve(){
cin>>p>>m;
ll t=p-1;
n=0;ans=0;
while(t){
idxp[++n]=t%2;
t/=2;
}
k=0;
M=m;
while(M){
idxm[++k]=M%2;
M/=2;
}
// reverse(idxm+1,idxm+1+k);reverse(idxp+1,idxp+1+n);
ll sum=0;
for(int i=max(n,k);i>=1;i--){
if(i>k){
sum=sum*2+idxp[i];
}
else{
if(idxm[i]==0){
if(idxp[i]==1) sum=sum*2+1;
else sum=sum*2;
}
else{
ll l=(sum*2+idxp[i])*pw[i-1],r=(sum*2+idxp[i])*pw[i-1]+pw[i-1]-1;
if(l==0) l=1;
// cout<<l<<' '<<p<<endl;
if(r>=1) ans+=max((ll)0,(r-1)/p-((l-1)/p+((l-1)%p==0?0:1))+1);
// cout<<fixed<<setprecision(10)<<(double)l/(double)p<<endl;
if(idxp[i]==0) sum=sum*2+1;
else sum=sum*2;
}
}
}
if((m^(p-1))%p==1) ans++;
cout<<ans<<endl;
}
int main(){
int T;
pw[0]=1;
for(int i=1;i<=69;i++) pw[i]=pw[i-1]*2;
cin>>T;
while(T--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
input:
3 2 0 7 11 1145141 998244353
output:
1 2 872
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 23ms
memory: 3560kb
input:
47595 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 2 26 2 27 2 28 2 29 2 30 2 31 2 32 2 33 2 34 2 35 2 36 2 37 2 38 2 39 2 40 2 41 2 42 2 43 2 44 2 45 2 46 2 47 2 48 2 49 2 50 2 51 2 52 2 53 2 54 2 55 2 56 2 57 2 58 2 59 2 60...
output:
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 53 53 ...
result:
ok 47595 lines
Test #3:
score: -100
Wrong Answer
time: 43ms
memory: 3664kb
input:
100000 11 34 71 35 11 45 53 28 3 67 17 38 41 2 23 8 47 26 79 98 89 47 97 33 43 95 97 98 29 79 29 48 67 27 37 3 97 72 71 97 67 53 23 77 71 12 101 92 89 63 61 71 59 94 97 2 29 64 53 74 47 78 67 0 97 66 79 81 3 48 67 87 79 88 59 63 17 25 61 37 67 64 79 93 67 92 89 0 59 88 11 29 29 5 13 47 101 80 3 12 8...
output:
3 1 5 1 24 3 1 0 0 2 1 1 2 2 3 2 1 1 1 2 1 3 0 1 1 3 2 1 2 2 1 0 1 2 16 2 2 2 2 1 1 2 2 0 2 4 1 3 1 4 1 1 13 45 1 1 4 1 3 2 1 3 1 1 2 1 7 1 1 2 1 1 0 1 2 2 1 3 2 9 1 2 1 1 32 1 1 2 1 1 0 1 3 1 1 3 1 2 1 3 2 1 0 2 2 0 1 1 1 3 2 2 1 4 5 1 1 3 2 0 3 2 2 1 4 1 1 9 0 2 2 2 1 1 3 1 2 2 1 1 0 2 2 11 21 2 3...
result:
wrong answer 5th lines differ - expected: '23', found: '24'