HDU 2136 Largest prime factor (prime number screening + playing table) __hdu

Source: Internet
Author: User
largest prime factor Time limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 9962 accepted Submission (s): 3514

Problem Description Everybody knows any number can be combined by the prime number.
Now, your task is telling me what position of the largest prime.
The position of Prime 2 is 1, Prime 3 are 2, and Prime 5 is 3, etc.
Specially, LPF (1) = 0.

Input each line would 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
Author Wiskey
Source
AC Code:
#include <iostream>  
#include <memory.h>  
#include <cstdlib>  
#include <cstdio>  
#include <cmath>  
#include <cstring>  
#include <string>  
#include <cstdlib>  
#include <iomanip>  
#include <vector>  
#include <list>  
#include <map>  
#include <algorithm>  
typedef long LL;  
using namespace std; 
Const LL MAXN=1E6;
Const LL mod=10000000; 
int a[maxn]={0};
Prime number filter: Hit the table 
int main ()
{
	
	int n,k=1;
	for (int i=2;i<maxn;i++)
	{
		if (a[i]==0)
		{
			a[i]=k++,//position for 
			(int j=i+i;j<maxn; J+=i)
			{
				a[j]=a[i];
	}} while (~SCANF ("%d", &n))
	{
		if (n==1) printf ("0\n"); 
		else
		cout<<a[n]<<endl;
	}
    return 0;	
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.