F - x = a^b

原题链接

题解

假如 b=2,则有 n2 个这样的数

假如 b=3,则有 n3 个这样的数

所以总共有 k=2log2(n)k 个这样的数

考虑去重

由于 n31e6,所以 a 不会超过 1e6,所以我们可以统计该范围内的所有 ak,k>2 的数,然后去除那些完全平方数

细节:

sqrt 精度会炸,要用 sqrtl

code

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

#define int long long


void solve() {
    int n;
    cin >> n;

    int ans =sqrtl(n);

    unordered_set<int> mp;
    for (int a = 2; a <= 1e6; a++)
    {
        int tem = a * a * a;
        while (tem <= n)
        {
            int sq = sqrtl(tem);
            if(sq*sq!=tem) mp.insert(tem);
            if (tem > n / a) break;  // 防止溢出
            tem *= a;
        }
    }
    ans += mp.size();
    cout << ans << '\n';
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int TT = 1;
    // cin >> TT;
    while (TT--) solve();
    return 0;
}



posted @   纯粹的  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示