結果
| 問題 |
No.344 ある無理数の累乗
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-02-13 03:40:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 756 bytes |
| コンパイル時間 | 1,354 ms |
| コンパイル使用メモリ | 158,796 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-22 06:10:56 |
| 合計ジャッジ時間 | 2,249 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int(i)=0;(i)<(n);++(i))
#define in(T,V) T V;cin>>V;
const int MOD = 1000;
// ((1+sqrt3)^n + (1-sqrt3)^n) - (1-sqrt3)^n
// |(1-sqrt3)^n| = (-0.73205...)^n < 1
struct OBJ{
ll r,d;
OBJ(ll r, ll d):r(r),d(d){};
const OBJ operator*(const OBJ &p) const {
ll resr = (r * p.r + d * p.d * 3) % MOD;
ll resd = (d * p.r + p.d * r) % MOD;
return OBJ(resr, resd);
}
};
const OBJ binpow(OBJ x, ll k){
if(k == 0) return OBJ(1,0);
if(k % 2 == 0) return binpow(x*x, k/2);
else return x * binpow(x, k-1);
}
int main(){
in(int,N);
OBJ res = binpow(OBJ(1,1), N);
cout << (res.r * 2 - 1 + N % 2 + MOD) % MOD << endl;
}