Largest prime factor
#include <iostream> #define max 1000001 int prime[max]; int main() { int i,j,n=0; memset(prime,-1,sizeof(prime)); prime[1]=0; for(i=2;i<max;i++) { if(prime[i]==-1) { n++; for(j=i;j<max;j+=i) prime[j]=n; } } while(~scanf("%d",&n)) { printf("%d\n",prime[n]); } return 0; }