QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#612520#6704. Happy EquationAndycipationAC ✓1ms3632kbC++20972b2024-10-05 11:42:582024-10-05 11:42:59

Judging History

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

  • [2024-10-05 11:42:59]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3632kb
  • [2024-10-05 11:42:58]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...) 42
#endif

int Power(long long b, int e, int md) {
  b %= md;
  if (b < 0) b += md;
  long long ret = 1;
  while (e > 0) {
    if (e & 1) {
      ret = ret * b % md;
    }
    b = b * b % md;
    e >>= 1;
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  auto Solve = [](int a, int p) {
    int md = (1 << p);
    if (a % 2 == 0) {
      int ret = 0;
      for (int x = 1; x < p; x++) {
        if ((Power(x, a, md) - Power(a, x, md)) % md == 0) {
          ret += 1;
        }
      }
      int e = (p + a - 1) / a;
      ret += (1 << p) / (1 << e) - (p - 1) / (1 << e);
      return ret;
    }
    if (a == 1) {
      return 1;
    }
    return 1;
  };
  
  int tt;
  cin >> tt;
  while (tt--) {
    int a, p;
    cin >> a >> p;
    cout << Solve(a, p) << '\n';
  }
  return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3620kb

input:

2
6 12
8 16

output:

1023
16383

result:

ok 2 number(s): "1023 16383"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3632kb

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