Toggle navigation
Home
Latest pastes
FAQ
Random
BitBin is shutting down!
Register
Login
Untitled
SUBMITTED BY:
Guest
DATE:
July 7, 2013, 5:07 p.m.
FORMAT:
Python
SIZE:
697 Bytes
Raw
Download
Tweet
HITS:
1113
Go to comments
Report
import
math
#prime factorization via the method of sieving
num
=
input
(
"input number:"
)
sqrt
=
long
(
math
.
floor
(
math
.
sqrt
(
num
)))
list
=
range
(
2
,
sqrt
+
1
)
#print "List:",list
prime
=
[]
for
i
in
range
(
1
,
long
(
math
.
sqrt
(
sqrt
))
+
1
):
temp
=
list
[
0
]
list
.
remove
(
list
[
0
])
prime
.
append
(
temp
)
list
=
[
x
for
x
in
list
if
x
%
temp
!=
0
]
prime
.
extend
(
list
)
factor
=
[]
flag
=
True
while
True
:
for
i
in
prime
:
if
num
%
i
==
0
:
factor
.
append
(
i
)
num
=
num
/
i
prime
=
[
x
for
x
in
prime
if
x
<=
long
(
math
.
floor
(
math
.
sqrt
(
num
)))
]
break
;
else
:
flag
=
False
if
flag
==
False
:
break
factor
.
append
(
num
)
print
factor
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus