QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#634584#7735. Primitive RootYurilyWA 19ms3708kbC++20884b2024-10-12 17:39:492024-10-12 17:39:50

Judging History

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

  • [2024-10-12 17:39:50]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:3708kb
  • [2024-10-12 17:39:49]
  • 提交

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+1;
	long long r=(ed-1)/p+1;
	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){	
			long long d=0;
			if((1ll<<i)&p)
				d=1;
			ans+=calc(st+(d<<i),(__int128)st+(d<<i)+(1ll<<i)-1);
			if((1ll<<i)==(m&(-m))){
				ans+=calc(st+((d^1)<<i),(__int128)st+((d^1)<<i)+(1ll<<i)-1);
				break;
			}
			else{
				st-=(d<<i);
				st+=(((d^1)<<i));
			}
		//	cout<<ans<<endl; 
		}
		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: 100
Accepted
time: 0ms
memory: 3708kb

input:

3
2 0
7 11
1145141 998244353

output:

1
2
872

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 19ms
memory: 3624kb

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
1
4
3
4
4
8
5
6
6
8
7
8
8
16
9
10
10
12
11
12
12
16
13
14
14
16
15
16
16
32
17
18
18
20
19
20
20
24
21
22
22
24
23
24
24
32
25
26
26
28
27
28
28
32
29
30
30
32
31
32
32
64
33
34
34
36
35
36
36
40
37
38
38
40
39
40
40
48
41
42
42
44
43
44
44
48
45
46
46
48
47
48
48
64
49
50
50
52
51
52
52
56
53...

result:

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