QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116495#6566. Power of DivisorsNYCU_Yamada#WA 23ms18728kbC++201.3kb2023-06-29 13:24:422023-06-29 13:24:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-29 13:24:43]
  • 评测
  • 测评结果:WA
  • 用时:23ms
  • 内存:18728kb
  • [2023-06-29 13:24:42]
  • 提交

answer

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

#define int int64_t

const int sq3C = 1'000'000;

bool chk_prime(int x) {
    for (int i = 2; i*i <= x; ++i) {
        if (x % i == 0) return false;
    }
    return true;
}

void solve() {
    int X; cin >> X;
    
    int sqX = sqrtl(X);
    for (int i = sqX-3; i <= sqX+3; ++i) {
        if (i * i == X and chk_prime(i)) return cout << i << "\n", void();
    }
    
    bitset<sq3C> is_prime; is_prime.set();
    vector<int> div_cnt(sq3C+1), max_pf(sq3C+1);
    div_cnt[1] = 1;
    for (int i = 2; i <= sq3C; ++i) {
        if (is_prime[i]) {
            max_pf[i] = i, div_cnt[i] = 2;
            for (int j = i+i; j <= sq3C; j += i) is_prime[j] = 0, max_pf[j] = i;
        }
        else {
            int j = i, cnt = 1;
            while (j % max_pf[i] == 0) j /= max_pf[i], ++cnt;
            div_cnt[i] = div_cnt[j] * cnt;
        }
    }
    
    for (int i = 1; i <= sq3C; ++i) {
        __int128_t val = 1;
        for (int exp = 1; exp <= div_cnt[i]; ++exp) {
            val *= i;
            if (val > X) break;
        }
        if (val == X) return cout << i << "\n", void();
    }
    
    cout << -1 << "\n";
}

int32_t main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    
    solve();
    
    return 0;
}

详细

Test #1:

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

input:

15625

output:

25

result:

ok single line: '25'

Test #2:

score: 0
Accepted
time: 23ms
memory: 18680kb

input:

64000000

output:

20

result:

ok single line: '20'

Test #3:

score: 0
Accepted
time: 22ms
memory: 18728kb

input:

65536

output:

-1

result:

ok single line: '-1'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3544kb

input:

1

output:

-1

result:

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