1 条题解
-
0
[GESP202403 五级] B-smooth 数(B-Smooth Numbers) 题解
思路分析
使用埃氏筛或线性筛在 / 时间内预处理 每个数的最大质因子
maxP[i](每次筛素数 时对所有倍数更新maxP[j] = p)。注意 没有质因子,对任意 (包括 ), 都是 -smooth 数(令maxP[1] = 0)。最后统计 中满足maxP[i] <= B的个数即可。参考代码
#include <iostream> using namespace std; const int MX = 1000005; int maxP[MX]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, B; if (!(cin >> n >> B)) return 0; for (int i = 2; i <= n; ++i) { if (maxP[i] == 0) { for (int j = i; j <= n; j += i) maxP[j] = i; } } int ans = 0; for (int i = 1; i <= n; ++i) { if (maxP[i] <= B) ++ans; } cout << ans << "\n"; return 0; }
- 1
信息
- ID
- 8566
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者