【HDU2136】Largest prime factor

来源:互联网 发布:组策略禁止安装软件 编辑:程序博客网 时间:2024/06/05 16:38

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2136
题解
水题
埃氏筛的同时把这个素数的倍数都标记为这个素数的序号
从小到大更新的同时就能保证一个数的序号是它的最大质因数

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int f[1000010],n;int main(){    int tot=0;    for(int i=2;i<=1e6;i++)        if(!f[i])        {            ++tot;            for(int j=i;j<=1e6;j+=i)    f[j]=tot;        }    while(~scanf("%d",&n))        printf("%d\n",f[n]);    return 0;}
原创粉丝点击