首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Problem three

2012-11-11 
Problem three.The question is :The prime factors of 13195 are 5, 7, 13 and 29.What is the largest p

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 1from math import sqrt,floordef 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

?

?

?

?

?

?

?

热点排行