QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#408256 | #6704. Happy Equation | _Dusker# | AC ✓ | 1ms | 3608kb | C++20 | 801b | 2024-05-09 22:02:31 | 2024-05-09 22:02:32 |
Judging History
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 << endl;
}
signed main()
{
#ifdef ONLINE_JUDGE
ioclear;
#endif
int t;
std::cin >> t;
while(t--)
solve();
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3516kb
input:
2 6 12 8 16
output:
1023 16383
result:
ok 2 number(s): "1023 16383"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3608kb
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 1048571 1 1 1 65532 1 1 16777204 1 1 16777212 16777210 1 32761 16777210 1 1 33554420 32761 1 16777204 1 2097142 8388603 262142 1 1 16777204 4194299 134217722 1 1 8388597 1 1 1 32761 1 1 1 268435449 524279 1 1 67108860 1 1 1 4194293 1048571 67108851 1 1 1 131064 1 1 167772...
result:
ok 1000 numbers