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)