Maximum prime factor of HDU 5108

Source: Internet
Author: User

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]);
}
}

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.