码迷,mamicode.com
首页 > 编程语言 > 详细

欧拉计划(python) problem 3

时间:2015-01-26 21:07:23      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

Problem 3

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

What is the largest prime factor of the number 600851475143 ?

python code:


import math
sqrt=math.sqrt


def func(x):
    m=int(sqrt(x)+1)
    for i in range(2,m):
        if x%i==0:
            return 0
    return 1


num=600851475143
n=sqrt(num)+1
n=int(n)
result=0
for i in range(2,n):
    if num%i==0:
        if func(i)==1:
            result=i
print(result)


result : 6857

time: <1s

欧拉计划(python) problem 3

标签:

原文地址:http://blog.csdn.net/zhangzhengyi03539/article/details/43158675

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!