結果
問題 | No.344 ある無理数の累乗 |
ユーザー |
![]() |
提出日時 | 2020-01-01 14:50:02 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 847 bytes |
コンパイル時間 | 150 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-11-22 04:49:21 |
合計ジャッジ時間 | 2,216 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
import sysread = sys.stdin.buffer.readreadline = sys.stdin.buffer.readlinereadlines = sys.stdin.buffer.readlinesMOD = 1000class Qint():def __init__(self,a,b):self.x = aself.y = bdef __mul__(self,other):x = self.x * other.x + 3 * self.y * other.yy = self.x * other.y + self.y * other.xreturn 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 *= xreturn self * x if n & 1 else xdef f(N):q = Qint(1,1) ** Nx = q.x * 2 % MODif N == 0:return 1elif N & 1:return xelse:return (x - 1) % MOD# f(0), f(2), f(12), f(123456789)N = int(read())answer = f(N)print(answer)