Maximum prime factor of HDU 5108
Alexander and Prime NumbersTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 706 Accepted Submission (s): 247
Problem descriptionalexander Ra has a little brother. He is new to programming. One day he is solving the following problem: Given an positive integer N, judge whether N is prime.
The problem above is quite easy, so Alexander gave him a new task: Given a positive integer N, find the minimal positive integer M, such that N/M is prime. if such M doesn' t exist, output 0.
Help him!
InputThere are multiple test cases (no more than 1,000). Each case contains only one positive integer N.
N ≤ 1,000,000,000 .
Number of cases N> 1,000,000 Is no more than 100.
OutputFor each case, output the requested M, or output 0 if no solution exists.
Sample Input
3456
Sample Output
1212
SourceBestCoder Round #19
Recommendheyang | We have carefully selected several similar problems for you: 5111 5110 5109 5107
Question: Find a minimum M for N, so that N/M = Prime is not explained. Simple code # include
# Include
# Include
# Include
Using namespace std;
Int f (int x)
{
Int flag = 0;
For (int I = 2; (I * I) <= x; I ++)
{
If (x % I = 0)
{
Flag = 1;
Break;
}
}
If (flag) return 0;
Return 1;
}
Int main ()
{
Int n;
Int mark [200005];
While (scanf ("% d", & n )! = EOF)
{
If (n = 1) {printf ("0 \ n"); continue ;}
Int count = 0, flag = 0;
For (int I = 1; (I * I) <= n; I ++)
{
If (n % I = 0) {mark [count ++] = I; mark [count ++] = n/I ;}
}
Sort (mark, mark + count );
Int I;
For (I = count-1; I> = 0; I --)
{
If (f (mark [I]) {break ;}
}
Printf ("% d \ n", n/mark [I]);
}
}