`
jonson
  • 浏览: 168580 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Problem three.

 
阅读更多

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

 

 

 

 

 

 

 

2
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics