Problem three.

本文介绍了一种高效求解大数最大质因数的方法。通过排除偶数、从平方根向下试探等技巧,显著减少了计算步骤。文章给出了具体的Python实现代码。

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

The question is :

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

What is the largest prime factor of the number 600851475143 ?

You may have a try first!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

the answer:

For this problem ,you can find some condtion:

1.if it is not even number,then you need not to check even numbers.

2.the factor can start with floor(sqrt(evil_big_number))

3.if it is not a factor then you need not to check prime.

use these candition you can get the result soon.

 

my soluation:

def isPrime(num):
  x = 2
  while x < num :
    if num %x == 0:
      return 0
    x = x + 1
  return 1

from math import sqrt,floor

def findBiggerPrimeFactor(num):
  factor = floor(sqrt(num))
  while factor  > 1 :
    if factor  % 2 != 0 and num % factor  == 0 and isPrime(factor )== 1:
      return factor 
    a = a -1

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值