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