Problem 3
Largest prime factor
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
最大质因数
13195的所有质因数为5、7、13和29。
600851475143最大的质因数是多少?
代码演示
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define N 600851475143LL
int main(){
long long num=N,ans,i=2;
while(i*i<=num){
if(num%i==0) ans=i;
while(num%i==0) num=num/i;
i++;
}
if(num!=1)ans=num;
printf("%d\n",ans);
return 0;
}
答案
6857