[Group] NOIP2012 universal prime factorization of

P1075 prime factorization of

The first day of the holiday will give a solution to a problem wrote the entry difficulty ......

This question outset I would like to be complicated: Egypt type sieve, sieve ...... however Euler open an array of 1e9's? Unrealistic.

Until you see dalao solution to a problem area with a unique decomposition theorem:

Fundamental Theorem of Arithmetic can be expressed as: a natural number greater than any. 1 N, if N is not a prime number, then N can be decomposed into a finite number of unique product of prime numbers N = ^ Pl A1 * P2 ^ A2 ^ * P3 A3 ..... . * Pn ^ AN , where P1 <P2 <P3 ...... <Pn prime-number, wherein the index is a positive integer ai. Such decomposition is called a standard factorization N. It was first proved by Euclid given.

--Baidu Encyclopedia

Then the subject of the request last a prime number, then find the first prime number, then divide it n it.

n% first prime number exactly = 0, as long as you find the first number can be divisible by n can be, without having to sift prime oh.

AC Code:

#include<bits/stdc++.h>
using namespace std;
int n,p;
int main()
{
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
        if(n%i==0)
        {
            printf("%d",n/i);
            return 0;
        }
}
View Code

 

Guess you like

Origin www.cnblogs.com/yige2019/p/11256387.html