Pythonのお勉強 Part31at TECH
Pythonのお勉強 Part31 - 暇つぶし2ch321: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