QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#728520#6566. Power of Divisorsahsoltan#WA 25ms7096kbC++141.9kb2024-11-09 15:20:362024-11-09 15:20:38

Judging History

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

  • [2024-11-09 15:20:38]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:7096kb
  • [2024-11-09 15:20:36]
  • 提交

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 l = 0, r = pow(x, 1. / d) + 10;
    while(r - l > 1) {
      ll m = (l + r) >> 1;
      if(bp(m, d) > x) r = m;
      else l = m;

      debug(l, m , r);
    }
    if(bp(l, d) == x) {
      if(div[l] == d) {
        ans = min(ans, l);
      }
    }
  }
  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: 21ms
memory: 7096kb

input:

64000000

output:

20

result:

ok single line: '20'

Test #3:

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

input:

65536

output:

-1

result:

ok single line: '-1'

Test #4:

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

input:

1

output:

1

result:

ok single line: '1'

Test #5:

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

input:

10

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

100

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

10000

output:

10

result:

ok single line: '10'

Test #8:

score: -100
Wrong Answer
time: 20ms
memory: 6980kb

input:

1000000000000000000

output:

-1

result:

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