前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >数学--数论--HDU 2136(素数筛选法)

数学--数论--HDU 2136(素数筛选法)

作者头像
风骨散人Chiam
发布2020-11-06 00:45:40
3770
发布2020-11-06 00:45:40
举报
文章被收录于专栏:CSDN旧文CSDN旧文

Everybody knows any number can be combined by the prime number. Now, your task is telling me what position of the largest prime factor. The position of prime 2 is 1, prime 3 is 2, and prime 5 is 3, etc. Specially, LPF(1) = 0. Input Each line will contain one integer n(0 < n < 1000000). Output Output the LPF(n). Sample Input 1 2 3 4 5 Sample Output 0 1 2 1 3

代码语言:javascript
复制
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
const int MAX = 1000000;
int prime[MAX];
int mark[MAX];

void init()
{
    for (int i = 2, n = 1; i < MAX; i++)
    {
        if (!prime[i])
        {
            mark[i] = n++;
            for (int j = i; j < MAX; j = j + i)
                prime[j] = i;
        }
    }
}
int main()
{
    int n;
    init();
    while (~scanf("%d", &n))
    {
        printf("%d\n", mark[prime[n]]);
    }
    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-12-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档