QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#728584#6566. Power of Divisorsahsoltan#WA 34ms7100kbC++141.8kb2024-11-09 15:29:242024-11-09 15:29:35

Judging History

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

  • [2024-11-09 15:29:35]
  • 评测
  • 测评结果:WA
  • 用时:34ms
  • 内存:7100kb
  • [2024-11-09 15:29:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#ifdef LOCAL
auto operator<<(auto& o, auto x) -> decltype(x.first, o);
auto operator<<(auto& o, auto x) -> decltype(x.end(), o) {
  o << "{";
  for (int i = 0; auto y : x) o << ", " + !i++ * 2 << y;
  return o << "}";
}
auto operator<<(auto& o, auto x) -> decltype(x.first, o) {
  return o << "(" << x.first << ", " << x.second << ")";
}
void __print(auto... x) { ((cerr << x << " "), ...) << endl; }
#define debug(x...) __print("[" #x "]:", x)
#else
#define debug(...) 2137
#endif

__int128 bp(__int128 a, __int128 b) {
  __int128 r = 1;
  while(b) {
    if(b & 1) r = r * a;
    a = a * a;
    b /= 2;
    if(a > 2e18 || r > 2e18) return 2e18;
  }
  return r;
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  ll x;
  cin >> x;
  if(x == 1) {
    cout << 1 << '\n';
    return 0;
  }

  vector<int> div(1e6 + 10);
  for(int i = 1; i < div.size(); i++) {
    for(int j = i; j < div.size(); j += i) div[j]++;
  }
  
  ll ans = 1e18;

  {
    ll n = sqrt(x);
    while(n * n < x) n++;
    while(n * n > x) n--;
    bool f = true;
    if(n * n == x) {
      for(ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
          f = false;
          break;
        }
      }
      if(f) {
        ans = n;
      }
    }
  }

  for(int d = 3; d <= 60; d++) {
    ll n = pow(x, 1.0 / d);
    while(bp(n, d) < x) n++;
    while(bp(n, d) > x) n--;
    if(bp(n, d) == x) {
      if(div[n] == d) {
        ans = min(ans, n);
      }
    }
  }
  if(ans == 1e18) cout << -1 << endl;
  else cout << ans << endl;
}

詳細信息

Test #1:

score: 100
Accepted
time: 21ms
memory: 6876kb

input:

15625

output:

25

result:

ok single line: '25'

Test #2:

score: 0
Accepted
time: 24ms
memory: 6980kb

input:

64000000

output:

20

result:

ok single line: '20'

Test #3:

score: 0
Accepted
time: 25ms
memory: 6876kb

input:

65536

output:

-1

result:

ok single line: '-1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

1

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 20ms
memory: 7096kb

input:

10

output:

-1

result:

ok single line: '-1'

Test #6:

score: 0
Accepted
time: 21ms
memory: 6976kb

input:

100

output:

-1

result:

ok single line: '-1'

Test #7:

score: 0
Accepted
time: 25ms
memory: 7100kb

input:

10000

output:

10

result:

ok single line: '10'

Test #8:

score: -100
Wrong Answer
time: 34ms
memory: 6912kb

input:

1000000000000000000

output:

-1

result:

wrong answer 1st lines differ - expected: '100', found: '-1'