HDU 2136 largest prime factor prime number screening method __ Hang Electric

Source: Internet
Author: User
give you a number, ask you to find the number of the largest prime factor in the list of prime numbers position.


largest prime factor Time limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)

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 HDU 2007-11 Programming Contest_warmup



#include <stdio.h>
#include <string.h>
#define MAXN 1000000+1000
int PRIME[MAXN];
int main ()
{
	int k=1;//initialization k is positioned as 1
	int i,j,n;
	memset (prime,0,sizeof (prime));
/* Filter location/for
	(i=2;i<maxn;i++)//To MAXN, not sqrt (MAXN)
	{
		if (!prime[i))//if (prime[i]==0)
		{ Position
			of the prime[i]=k;//prime number I for
			(j=i+i;j<maxn;j+=i)
			{
				prime[j]=k;//constructs the position of the temporary maximum prime number factor of J
			}
			k++
		}
	}
	while (~SCANF ("%d", &n))
	{
		printf ("%d\n", Prime[n]);
	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.