結果

問題 No.344 ある無理数の累乗
ユーザー 🐬hec🐬hec
提出日時 2016-02-12 22:59:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,183 bytes
コンパイル時間 3,076 ms
コンパイル使用メモリ 160,104 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 03:22:26
合計ジャッジ時間 3,059 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))

using namespace std;
const int mod=1000;
int a[2][2]{{1,3},{1,1}},b[2][2];


void mul(int a[2][2],int b[2][2]){
	int tmpa[2][2],tmpb[2][2];
	rep(i,2)rep(j,2) tmpa[i][j]=a[i][j],tmpb[i][j]=b[i][j];
	rep(i,2)rep(j,2) a[i][j]=0;
	rep(i,2)rep(k,2)rep(j,2) a[i][j]+=tmpa[i][k]*tmpb[k][j];
	rep(i,2)rep(j,2) a[i][j]%=mod;
}

void power(int n){
	rep(i,2)rep(j,2) b[i][j]=(i==j);
	while(n){
		if(n&1) mul(b,a);
		mul(a,a);
		n>>=1;
	}
	return;
}


int main(void){
	int n;
	cin >> n;
	power(n);
	int ans=2*b[0][0];
	if(n%2==0) ans+=mod-1; 
	cout << ans%mod << endl;
}
0