记录编号 600920 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 3850.[春季测试 2023]幂次 最终得分 100
用户昵称 GravatarXZDZD 是否通过 通过
代码语言 C++ 运行时间 1.544 s
提交时间 2025-05-21 13:12:33 内存使用 14.35 MiB
显示代码纯文本
#include<bits/stdc++.h>
#include <cstdio>
#define int long long
const int N = 1e6 + 10;
using namespace std;
int n, k, ans = 0;
int QAQ (int a,int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = ans * a;
        b >>= 1;
        a *= a;
    }
    return ans;
}
void solve () {
    cin >> n >> k;
    int x = 0;
    if (k == 1) return cout << n, void();
    set <int> a;
    for (int i = 2; i * i * i <= n; ++i) {
        int temp = i * i;int m = 2;
        while (temp <= n/i) {
            temp *= i, m++;
            if (m < k) continue;
            if (a.count(temp)) continue;
            if ((long long) sqrtl(temp) * sqrtl(temp) == temp) x++;
            a.insert(temp);
            ans++;
        }
    }
    if (k >= 3) cout << ans + 1;
    else cout << (long long) sqrtl(n) + ans - x;
}
signed main() {
    freopen("power.in","r",stdin);
    freopen("power.out","w",stdout);
    solve();
    return 0;
}