QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#693183#7735. Primitive RootsjcxWA 0ms3892kbC++231.1kb2024-10-31 15:40:412024-10-31 15:40:56

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 15:40:56]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3892kb
  • [2024-10-31 15:40:41]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<random>
#include<ctime>
using namespace std;
#define re int
#define ll long long
inline ll read(){
    ll x=0,ff=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')ff=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
    return x*ff;
}
inline int hbit(ll x){
	for(re i=59;i>=0;i--)
		if((x>>i)&1)return i;
	return 23333;
}
int main(){
	int t=read(),x,y;ll p,m,ss;
	while(t--){
		p=read();m=read();
		if(m==0){
			if(p==2)puts("1");
			else puts("0");
			continue;
		}
		if(p==2&&m<=3){
			if(m<2)puts("1");
			else puts("2");
			continue;
		}
		x=hbit(p-1);y=hbit(m);
		if(x>=y){
			if(m>=p)puts("1");
			else puts("0");
			continue;
		}
		ll u=m&(((1ll<<(y+1))-1)^((1ll<<(x+1))-1));
		ll v=m-u;
		ss=(u-1)/p+(((u-1)%p)>=1);
		ll _u=u;u%=p;u^=((p+1-u)%p)^(p-1);
		if(u<=v)ss++;
		_u%=p;
		if(_u+p<(1ll<<(x+1))){
			_u^=((p+1-_u)%p+p)^(p-1);
			if(_u<=v)ss++;
		}
		printf("%lld\n",ss);
	}
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3892kb

input:

3
2 0
7 11
1145141 998244353

output:

1
1
872

result:

wrong answer 2nd lines differ - expected: '2', found: '1'