1.5 43: Prime factor decomposition

Description
Knowing that a positive integer n is the product of two different prime numbers, try to find the larger prime number.

Input
There is only one line of input and contains a positive integer n.

For 60% of the data, 6 ≤ n ≤ 1000.
For 100% data, 6 ≤ n ≤ 2*10^9.
Output The
output is only one line, containing a positive integer p, the larger prime number.
Sample input
21
Sample output
7

//CPP实现
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    
    
	int n,t,r,i;
	cin>>n;
	t = sqrt(n);
	for(i=2;i<=t;i++)
	{
    
    
		if(n%i != 0)
		{
    
    
			continue;
		}
		r = n/i;
		cout<<r<<endl;		
	}
	return 0;
}
##Python实现
n = int(input())
for i in range(2, n):
    if n%i == 0:
        print(int(n/i))
        break

Guess you like

Origin blog.csdn.net/yansuifeng1126/article/details/112945040