201412022200-hd-largest Prime factor

Source: Internet
Author: User

Largest prime factorTime limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) Total Submission (s): 7195 Accepted Submission (s): 2554

problem DescriptionEverybody knows any number can is combined by the prime number.
Now, your task was telling me what position of the largest prime factor.
The position of Prime 2 is 1, Prime 3 are 2, and Prime 5 is 3, etc.
Specially, LPF (1) = 0.
 
InputEach line would contain one integer n (0 < n < 1000000).
 
OutputOutput the LPF (n).
 
Sample Input
12345
 
Sample Output
 01213     solution thinking    thought for a long time, or the use of the method of playing the table, with the prime number of the table, but not just because of the prime number and mark it, but if it is a prime number, it and its multiples of the position of the prime number to mark. Because I is constantly changing, so if it is 6, the first mark is 2, the back can be replaced with the three marks.   code    
# Include<stdio.h> #include <string.h>int a[1100000];int main () {int N,i,j,now;memset (a,0,sizeof (a));//initialization , mark it all as 0 a[1]=0;now=0;//mark position, that is, the number of for (i=2;i<=1000000;i++) {if (a[i]==0)//If it is prime {now++;for (j=i;j<=1000000; j+=i) a[j]=now;//all multiples in the range are marked with now, and the}//i is constantly increasing, and the maximum quality factor is constantly being replaced. } while (scanf ("%d", &n)!=eof) {printf ("%d\n", A[n]);} return 0;} 



201412022200-hd-largest Prime factor

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.