Pythonのお勉強 Part3 ..
[2ch|▼Menu]
321:317
09/01/21 01:57:21
nのべき乗の1の位が、ある周期で循環することを利用して指数を小さくしてみた。

# coding: utf8

def cycle(n):
    i = n*n % 10
    lst = [i]
    while n != i:
        i = i*n % 10
        lst.append(i)
    return lst

def main():
    cycles = [cycle(i) for i in xrange(10)]
    clen = [len(item) for item in cycles]

    for i in range(10):
        print i, cycles[i]
    print ""

    for n in xrange(1, 1000):
        cl = clen[n%10]
        nn = pow(n, cycles[n%10][n%cl])
        nnn1 = pow(n, nn, 10)
        print n, nnn1
        

if __name__ == '__main__':
    main()



次ページ
続きを表示
1を表示
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
暇つぶし2ch

5385日前に更新/69 KB
担当:undef