Problem 3 Largest prime factor

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37345402/article/details/82996425

Problem 3 Largest prime factor

 https://projecteuler.net/problem=3

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

题意:找出一个合数的最大质数因子

c++

#include<iostream>
using namespace std;
int f(long long x){
	long long i=2;
	while(x>1){
		if(x%i==0){
			x/=i;
		}else{
			i++;
		}
	}
	return i;
} 
int main(){
	cout<<f(600851475143)<<endl;
	return 0;
}

//6857

猜你喜欢

转载自blog.csdn.net/m0_37345402/article/details/82996425
今日推荐