mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
all Long constants have an L suffix, not l;
added an output() function to move the I/O out of the algorithm
This commit is contained in:
parent
0cc19450e2
commit
0b2b440a13
1 changed files with 11 additions and 8 deletions
|
@ -11,20 +11,23 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
k, a, b, a1, b1 = 2l, 4l, 1l, 12l, 4l
|
k, a, b, a1, b1 = 2L, 4L, 1L, 12L, 4L
|
||||||
while 1:
|
while 1:
|
||||||
# Next approximation
|
# Next approximation
|
||||||
p, q, k = k*k, 2l*k+1l, k+1l
|
p, q, k = k*k, 2L*k+1L, k+1L
|
||||||
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
|
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
|
||||||
# Print common digits
|
# Print common digits
|
||||||
d, d1 = a/b, a1/b1
|
d, d1 = a/b, a1/b1
|
||||||
#print a, b, a1, b1
|
|
||||||
while d == d1:
|
while d == d1:
|
||||||
# Use write() to avoid spaces between the digits
|
output(d)
|
||||||
sys.stdout.write(`int(d)`)
|
a, a1 = 10L*(a%b), 10L*(a1%b1)
|
||||||
# Flush so the output is seen immediately
|
|
||||||
sys.stdout.flush()
|
|
||||||
a, a1 = 10l*(a%b), 10l*(a1%b1)
|
|
||||||
d, d1 = a/b, a1/b1
|
d, d1 = a/b, a1/b1
|
||||||
|
|
||||||
|
def output(d):
|
||||||
|
# Use write() to avoid spaces between the digits
|
||||||
|
# Use int(d) to avoid a trailing L after each digit
|
||||||
|
sys.stdout.write(`int(d)`)
|
||||||
|
# Flush so the output is seen immediately
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue