Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
1c8230b7
Kaydet (Commit)
1c8230b7
authored
Ara 18, 1991
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Adapt to mixed-mode arithmetic, and added a warning comment.
üst
97dddba1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
fact.py
Demo/scripts/fact.py
+8
-6
No files found.
Demo/scripts/fact.py
Dosyayı görüntüle @
1c8230b7
#! /usr/local/python
#! /usr/local/python
# Factorize numbers, slowly.
# Factorize numbers.
# This version uses plain integers and is thus limited to 2**31-1.
# The algorithm is not efficient, but easy to understand.
# If there are large factors, it will take forever to find them,
# because we try all odd numbers between 3 and sqrt(n)...
import
sys
import
sys
from
math
import
sqrt
from
math
import
sqrt
...
@@ -17,13 +19,13 @@ def fact(n):
...
@@ -17,13 +19,13 @@ def fact(n):
res
.
append
(
2
)
res
.
append
(
2
)
n
=
n
/
2
n
=
n
/
2
# Try odd numbers up to sqrt(n)
# Try odd numbers up to sqrt(n)
limit
=
int
(
sqrt
(
float
(
n
+
1
))
)
limit
=
sqrt
(
n
+
1
)
i
=
3
i
=
3
while
i
<=
limit
:
while
i
<=
limit
:
if
n
%
i
=
0
:
if
n
%
i
=
0
:
res
.
append
(
i
)
res
.
append
(
i
)
n
=
n
/
i
n
=
n
/
i
limit
=
int
(
sqrt
(
float
(
n
+
1
))
)
limit
=
sqrt
(
n
+
1
)
else
:
else
:
i
=
i
+
2
i
=
i
+
2
res
.
append
(
n
)
res
.
append
(
n
)
...
@@ -32,12 +34,12 @@ def fact(n):
...
@@ -32,12 +34,12 @@ def fact(n):
def
main
():
def
main
():
if
len
(
sys
.
argv
)
>
1
:
if
len
(
sys
.
argv
)
>
1
:
for
arg
in
sys
.
argv
[
1
:]:
for
arg
in
sys
.
argv
[
1
:]:
n
=
int
(
eval
(
arg
)
)
n
=
eval
(
arg
)
print
n
,
fact
(
n
)
print
n
,
fact
(
n
)
else
:
else
:
try
:
try
:
while
1
:
while
1
:
n
=
in
t
(
input
()
)
n
=
in
put
(
)
print
n
,
fact
(
n
)
print
n
,
fact
(
n
)
except
EOFError
:
except
EOFError
:
pass
pass
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment