-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathsolution_1.py
More file actions
48 lines (39 loc) · 880 Bytes
/
solution_1.py
File metadata and controls
48 lines (39 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
# coding=utf-8
#
# Python Script
#
# Copyleft © Manoel Vilela
#
#
from sys import version_info
if version_info >= (3, 0):
xrange = range
"""
Largest prime factor
Problem 3
Published on Friday, 2nd November 2001, 06:00 pm; Solved by 264184
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
"""
def prime_gen(n):
for i in xrange(2, n):
prime = True
if i % 2 == 0 and i != 2:
continue
sqrtp = int(i ** 1 / 2)
for j in xrange(2, sqrtp):
if j % 2 == 0:
continue
if i % j == 0:
prime = False
break
if prime:
yield i
num = 600851475143
for i in prime_gen(num):
if num % i == 0:
num /= i
if num <= 1:
print(i)
break