結果

問題 No.344 ある無理数の累乗
ユーザー rpy3cpp
提出日時 2016-02-12 23:23:41
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 422 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-09-22 04:56:13
合計ジャッジ時間 1,906 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

def mult(a, b, c, d):
    return (a * c + b * d * 3) % 1000, (a * d + b * c) % 1000

def mypow(n):
    pow2 = (1, 1)
    ans = (1, 0)
    while n:
        if n & 1:
            ans = mult(*ans, *pow2)
        pow2 = mult(*pow2, *pow2)
        n >>= 1
    return ans

def solve(n):
    a, b = mypow(n)
    if n & 1:
        return (a * 2) % 1000
    else:
        return (a * 2 - 1) % 1000

n = int(input())
print(solve(n))
0