結果

問題 No.344 ある無理数の累乗
ユーザー rpy3cpprpy3cpp
提出日時 2016-02-12 23:23:41
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 422 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 11,864 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2023-10-22 03:30:38
合計ジャッジ時間 2,019 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,112 KB
testcase_01 AC 31 ms
10,112 KB
testcase_02 AC 29 ms
10,112 KB
testcase_03 AC 26 ms
10,112 KB
testcase_04 AC 27 ms
10,112 KB
testcase_05 AC 26 ms
10,112 KB
testcase_06 AC 26 ms
10,112 KB
testcase_07 AC 28 ms
10,112 KB
testcase_08 AC 25 ms
10,112 KB
testcase_09 AC 28 ms
10,112 KB
testcase_10 AC 26 ms
10,112 KB
testcase_11 AC 25 ms
10,112 KB
testcase_12 AC 24 ms
10,112 KB
testcase_13 AC 25 ms
10,112 KB
testcase_14 AC 26 ms
10,112 KB
testcase_15 AC 25 ms
10,112 KB
testcase_16 AC 25 ms
10,112 KB
testcase_17 AC 25 ms
10,112 KB
testcase_18 AC 24 ms
10,112 KB
testcase_19 AC 25 ms
10,112 KB
testcase_20 AC 25 ms
10,112 KB
testcase_21 AC 27 ms
10,112 KB
testcase_22 AC 25 ms
10,112 KB
testcase_23 AC 26 ms
10,112 KB
testcase_24 AC 26 ms
10,112 KB
testcase_25 AC 27 ms
10,112 KB
testcase_26 AC 27 ms
10,112 KB
testcase_27 AC 25 ms
10,112 KB
testcase_28 AC 26 ms
10,112 KB
testcase_29 AC 25 ms
10,112 KB
権限があれば一括ダウンロードができます

ソースコード

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