Chinaunix首页 | 论坛 | 博客
  • 博客访问: 86591
  • 博文数量: 47
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 625
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-11 12:11
文章分类

全部博文(47)

文章存档

2008年(47)

我的朋友

分类:

2008-11-13 14:06:54

Problem 26

13 September 2002

A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given:

1/20.5
1/30.(3)
1/40.25
1/50.2
1/60.1(6)
1/70.(142857)
1/80.125
1/90.(1)
1/100.1

Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle.

Find the value of d 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.

如果d只有2和5两个约数,则没有1/d循环小数,如果d还有其他的约数,则1/d的循环小数的长度和d除去其所有2和5的约数的值d1的循环小数长度相同,比如6就和3的循环小数长度相同

def fun26():
    result = (0,0)
    for i in range(2, 1000):
        print i
        while i%2 == 0:
            i /= 2
        while i%5 == 0:
            i /= 5
        if i == 1:
            continue

        count  = 9
        length = 1
        while 1:
            if count%i == 0:
                if length > result[0]:
                    result = (length, i)
                break
            else:
                count   = count*10 + 9
                length += 1
    return result
answer is 983, the length of recurring cycle is 982
阅读(531) | 评论(1) | 转发(0) |
0

上一篇:Problem 24

下一篇:Problem 28

给主人留下些什么吧!~~

chinaunix网友2009-06-12 01:48:52

不明白为什么除去全部2和5后能被9整除循环小数就是1位,被99整除就是2位……