|
11 | 11 | import sys |
12 | 12 |
|
13 | 13 | def main(): |
14 | | - k, a, b, a1, b1 = 2L, 4L, 1L, 12L, 4L |
15 | | - while 1: |
16 | | - # Next approximation |
17 | | - p, q, k = k*k, 2L*k+1L, k+1L |
18 | | - a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1 |
19 | | - # Print common digits |
20 | | - d, d1 = a/b, a1/b1 |
21 | | - while d == d1: |
22 | | - output(d) |
23 | | - a, a1 = 10L*(a%b), 10L*(a1%b1) |
24 | | - d, d1 = a/b, a1/b1 |
| 14 | + k, a, b, a1, b1 = 2L, 4L, 1L, 12L, 4L |
| 15 | + while 1: |
| 16 | + # Next approximation |
| 17 | + p, q, k = k*k, 2L*k+1L, k+1L |
| 18 | + a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1 |
| 19 | + # Print common digits |
| 20 | + d, d1 = a/b, a1/b1 |
| 21 | + while d == d1: |
| 22 | + output(d) |
| 23 | + a, a1 = 10L*(a%b), 10L*(a1%b1) |
| 24 | + d, d1 = a/b, a1/b1 |
25 | 25 |
|
26 | 26 | def output(d): |
27 | | - # Use write() to avoid spaces between the digits |
28 | | - # Use int(d) to avoid a trailing L after each digit |
29 | | - sys.stdout.write(`int(d)`) |
30 | | - # Flush so the output is seen immediately |
31 | | - sys.stdout.flush() |
| 27 | + # Use write() to avoid spaces between the digits |
| 28 | + # Use str() to avoid the 'L' |
| 29 | + sys.stdout.write(str(d)) |
| 30 | + # Flush so the output is seen immediately |
| 31 | + sys.stdout.flush() |
32 | 32 |
|
33 | 33 | main() |
0 commit comments