QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#720708#7735. Primitive RootguangxuautumnWA 0ms3608kbC++14808b2024-11-07 13:45:172024-11-07 13:45:17

Judging History

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

  • [2024-11-07 13:45:17]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3608kb
  • [2024-11-07 13:45:17]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve()
{
	ll p, m;
	cin >> p >> m;

	if(m == 0) {
		if(p == 2) cout << 1 << endl;
		else cout << 0 << endl;

		return;
	}

	//for(int i = 1; i < 1000; i ++) {
	//	if(((p * i + 1) % p) ^ (p - 1) > (p * i + 1) % p) {
	//		cout << 1;
	//	}else cout << 0;
	//}
	ll ans = 1;
	ll maxk = (m - 1) / p;
	if(((p * maxk + 1) ^ (p - 1)) > m) {
		//cout << maxk << ' ' << ((p * maxk + 1) ^ (p - 1)) << endl;
		ans --;
	} else {
		if(((p * (maxk + 1) + 1) ^ (p - 1)) < m) {
			ans ++;
		}
	}
	//for(ll i = maxk + 1; ; i ++) {
	//	if(((p * i + 1)) ^ (p - 1) > m) break;
	//	else ans ++;
	//}

	cout << maxk + ans << endl;

}

int main()
{
	int t;
	cin >> t;

	while(t--)
		solve();

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 0
7 11
1145141 998244353

output:

1
1
872

result:

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