欧拉计划第3题

博客围绕求最大质因数展开,给出13195的质因数为5、7、13和29,提出求600851475143最大质因数的问题,还包含代码演示部分。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值