QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408126#6704. Happy Equationcur_nxtWA 1ms3612kbC++20804b2024-05-09 18:49:292024-05-09 18:49:31

Judging History

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

  • [2024-05-09 18:49:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3612kb
  • [2024-05-09 18:49:29]
  • 提交

answer

#include <bits/stdc++.h>
#define ioclear std::ios::sync_with_stdio(false);std::cin.tie(nullptr);std::cout.tie(nullptr);
#define endl '\n'
#define int long long 

using namespace std;

int qp(int x, int k, int mod)
{
	int ans = 1;
	while(k)
	{
		if(k & 1)
			ans = ans * x % mod;
		x = x * x % mod;
		k >>= 1;
	}
	return ans % mod;
}

void solve()
{
	int a, p, ans = 0;
	std::cin >> a >> p;
	if(a & 1)
	{
		std::cout << "1\n";
		return;
	}
	int m = (1ll << p);
	for(int x = 1; x < p; x++)
		if(qp(a, x, m) == qp(x, a, m))
			ans++;
	int q1 = (p + a - 1) / a;
	ans += (1ll << (p - q1));
	q1 = 1ll << q1;
	ans -= p / q1;
	std::cout << ans + 1 << endl;
}

signed main()
{
	#ifdef ONLINE_JUDGE
	ioclear;
	#endif
	int t;
	std::cin >> t;
	while(t--)
		solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3504kb

input:

2
6 12
8 16

output:

1023
16383

result:

ok 2 number(s): "1023 16383"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3612kb

input:

1000
959668315 17
173599849 18
452866086 16
984874375 15
346061855 21
440851881 22
224960642 16
176079916 16
656766412 21
283466925 25
20353211 27
691728649 20
772055116 17
459468637 21
206618043 15
987058694 25
621275781 22
787193761 15
812760680 25
993799948 25
126264161 18
897813346 16
762713004 ...

output:

1
1
32761
1
1
1
32761
32765
1048572
1
1
1
65533
1
1
16777205
1
1
16777213
16777211
1
32761
16777211
1
1
33554420
32761
1
16777205
1
2097142
8388603
262143
1
1
16777205
4194300
134217722
1
1
8388597
1
1
1
32761
1
1
1
268435450
524279
1
1
67108861
1
1
1
4194294
1048572
67108852
1
1
1
131064
1
1
167772...

result:

wrong answer 9th numbers differ - expected: '1048571', found: '1048572'