首页 > 代码库 > HDU 2136 Largest prime factor

HDU 2136 Largest prime factor

水题,晒一遍素数并标注就OK了。


#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<bitset>
#include<vector>
#include<cmath>

#define INF 0x7fffffff
#define eps 1e-8
#define LL long long
#define PI 3.141592654
#define CLR(a,b) memset(a,b,sizeof(a))
#define FOR(i,a,n) for(int i= a;i< n ;i++)
#define FOR0(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define debug puts("==fuck==")
#define acfun std::ios::sync_with_stdio(false)

#define SIZE 1000000+1
using namespace std;

int prime[SIZE];
int main()
{

    CLR(prime,0);
    int k=1;
    for(int i=2;i<SIZE;i++)
    {
        if(prime[i])continue;
        prime[i]=k++;
        for(int j=2;i*j<SIZE;j++)
        prime[i*j]=prime[i];
    }
    int n;
    while(~scanf("%d",&n))
    {
        printf("%d\n",prime[n]);
    }
}



HDU 2136 Largest prime factor