赞
踩
输出a/b的循环小数表示以及循环节的长度。例如aa =5,bb =43 ,小数表示为0.(116279069767441860465),循环节长度为21。
- a, b = (int(x) for x in input().split(' '))
- l = []
- mod = a % b
- i = 300
- while i > 0:
- xs = (mod * 10) // b
- mod = (mod * 10) % b
- l.append(xs)
- i -= 1
- for i in range(1, len(l) + 1): # i指循环节长度
- m = 1
- for j in range(i):
- if l[j] != l[j + i]:
- m = 0
- break
- if m == 1: #验算
- p = i
- if l[2] == l[2 + i]:
- break
- print(p)
- print('0.(', end='')
- for i in range(p):
- print(l[i], end='')
- print(')')
运行结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。