結果

問題 No.344 ある無理数の累乗
ユーザー maspymaspy
提出日時 2020-01-01 14:50:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 847 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 7,960 KB
最終ジャッジ日時 2023-08-14 09:19:54
合計ジャッジ時間 1,941 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,864 KB
testcase_01 AC 15 ms
7,876 KB
testcase_02 AC 16 ms
7,808 KB
testcase_03 AC 14 ms
7,956 KB
testcase_04 AC 14 ms
7,908 KB
testcase_05 AC 14 ms
7,812 KB
testcase_06 AC 14 ms
7,960 KB
testcase_07 AC 14 ms
7,892 KB
testcase_08 AC 15 ms
7,824 KB
testcase_09 AC 14 ms
7,808 KB
testcase_10 AC 14 ms
7,912 KB
testcase_11 AC 14 ms
7,876 KB
testcase_12 AC 13 ms
7,820 KB
testcase_13 AC 13 ms
7,960 KB
testcase_14 AC 14 ms
7,744 KB
testcase_15 AC 14 ms
7,812 KB
testcase_16 AC 15 ms
7,748 KB
testcase_17 AC 14 ms
7,808 KB
testcase_18 AC 14 ms
7,820 KB
testcase_19 AC 13 ms
7,872 KB
testcase_20 AC 13 ms
7,816 KB
testcase_21 AC 12 ms
7,792 KB
testcase_22 AC 14 ms
7,836 KB
testcase_23 AC 14 ms
7,916 KB
testcase_24 AC 14 ms
7,788 KB
testcase_25 AC 14 ms
7,788 KB
testcase_26 AC 13 ms
7,908 KB
testcase_27 AC 14 ms
7,812 KB
testcase_28 AC 14 ms
7,872 KB
testcase_29 AC 14 ms
7,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 1000

class Qint():
    def __init__(self,a,b):
        self.x = a
        self.y = b
    def __mul__(self,other):
        x = self.x * other.x + 3 * self.y * other.y
        y = self.x * other.y + self.y * other.x
        return Qint(x%MOD,y%MOD)
    def __repr__(self):
        return '({}) + ({})sqrt 3'.format(self.x, self.y)
    def __pow__(self,n):
        if n == 0:
            return Qint(1,0)
        x = self ** (n//2)
        x *= x
        return self * x if n & 1 else x

def f(N):
    q = Qint(1,1) ** N
    x = q.x * 2 % MOD
    if N == 0:
        return 1
    elif N & 1:
        return x
    else:
        return (x - 1) % MOD

# f(0), f(2), f(12), f(123456789)

N = int(read())
answer = f(N)
print(answer)
0