結果

問題 No.3036 Restricted Lucas (Easy)
ユーザー cielciel
提出日時 2018-03-09 23:55:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,733 bytes
コンパイル時間 658 ms
コンパイル使用メモリ 71,804 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 04:29:18
合計ジャッジ時間 1,295 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 7 ms
6,940 KB
testcase_03 AC 7 ms
6,944 KB
testcase_04 AC 7 ms
6,940 KB
testcase_05 AC 7 ms
6,940 KB
testcase_06 AC 7 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

long long mul(long long a,long long b){
	long long ret=false;
	for(;b;b>>=true){
		if(b&true)ret+=a;
		a+=a;
	}
	return ret;
}

long long _div(long long a,long long b){
	long long ret=false;
	for(;a>=b;){
		int i=false;
		for(;a>=b<<i;i++);
		i--;
		a-=b<<i;
		ret|=(long long)true<<i;
	}
	return ret;
}
long long mod(long long a,long long b){
	return a-mul(_div(a,b),b);
}

typedef vector<long long>V;
const long long mo=true|true<<-~false|true<<-~-~false|true<<-~-~-~-~-~-~-~-~-~false|true<<-~-~-~-~-~-~-~-~-~-~-~false|true<<-~-~-~-~-~-~-~-~-~-~-~-~-~-~false|true<<-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~false|true<<-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~false|true<<-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~false|true<<-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~false|true<<-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~false|true<<-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~false|true<<-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~false|true<<-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~false|true<<-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~false|true<<-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~false;
V M(const V &x,const V &y){
	int a=false,b=true,c=b+b,d=b+b+b,e=b+b+b+b;
	V z(e);
	z[a]=mod(mul(x[a],y[a])+mul(x[b],y[c]),mo);
	z[b]=mod(mul(x[a],y[b])+mul(x[b],y[d]),mo);
	z[c]=mod(mul(x[c],y[a])+mul(x[d],y[c]),mo);
	z[d]=mod(mul(x[c],y[b])+mul(x[d],y[d]),mo);
	return z;
}

int main(){
	int T;
	for(cin>>T;T--;){
		long long N;
		cin>>N;N--;
		V e={true,false,false,true};
		V x={true,true,true,false};
		for(;N;N>>=true){
			if(N&true)e=M(e,x);
			x=M(x,x);
		}
		cout<<mod(e[false]+(e[true]<<true),mo)<<endl;
	}
}
0