HDU 2136 Largest prime factor (screening method for prime numbers)

Source: Internet
Author: User

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


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

Authorwiskey

The main topic: Each prime number in the list of primes has a ordinal, set 1 of the sequence number is 0, then 2

The ordinal number of 1,3 is the ordinal number of 2,5 is 3, and so on. The output is now required to

The number of the maximum mass factor of the given N, 0<n<1000000.


#include <iostream> #include <stdio.h>using namespace std;int pi;bool flag[1000010];int in;int n;int a[ 1000010];int Getprime () {for    (int i=2;i<1000010;++i)    {        if (!flag[i])        {            in++;            for (int j=i;j<1000010;j+=i)            {                flag[j]=true;                a[j]=in;//record sequence number            }        }    }}int Main (int argc, char *argv[]) {    //freopen ("2136.in", "R", stdin);    Getprime ();    while (scanf ("%d", &n)!=eof)    {        printf ("%d\n", A[n]);    }    return 0;}


HDU 2136 Largest prime factor (screening method for prime numbers)

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.