TYVJ P2067 (prime factor decomposition)

Source: Internet
Author: User

P2067-[NOIP2012P1] prime factor decomposition
From luchangzhou Normal (OI)
Total time limit: 10 s memory limit: 128 MB code length limit: 64 KB
Background

NOIP2012
Description

We know that positive integer n is the product of two different prime numbers, and try to find the larger prime number.
Input Format: InputFormat

The input contains only one row and contains a positive integer n.
Output Format: OutputFormat

The output contains only one row and a positive integer p, that is, the larger prime number.
Sample input SampleInput [Copy Data]

21
Sample output SampleOutput [Copy Data]

7
Data range and comment Hint

[Data Scope]
For 60% of data, 6 ≤ n ≤ 1000
For 100% of data, 6 ≤ n ≤ 2*10 ^ 9
Source

NOIP2012

O (√ n)
Note that you need to enumerate 1-√ n instead of √ n-n. The quantity level is much different.


[Cpp]
# Include <cstdio>
# Include <cstring>
# Include <cmath>
# Include <cstdlib>
# Include <cctype>
# Include <iostream>
# Include <functional>
# Include <algorithm>
Using namespace std;
# Define MAXN (100000 + 10)
# Define MAXAi (1000000000 + 10)
Int n;
Int main ()
{
Cin> n;
For (int I = 2; I <= n; I ++)
If (! (N % I ))
{
Cout <n/I <endl; return 0;
}


}

 

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.