結果

問題 No.3036 Restricted Lucas (Easy)
ユーザー okadukiokaduki
提出日時 2018-04-01 23:23:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,783 bytes
コンパイル時間 726 ms
コンパイル使用メモリ 78,504 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 12:54:49
合計ジャッジ時間 1,350 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

LL MOD;

int zero;
LL one;
LL two;
LL three;
LL four;
LL five;
LL six;
LL seven;
LL eight;
LL nine;
LL ten;

#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,zero,n)

LL mod(LL a){
  return div(a, MOD).rem;
}

LL mul(LL a, LL b){
  return mod(multiplies<LL>()(a,b));
}

VVL mul(const VVL& a, const VVL& b){
  VVL tmp(two, VL(two));
  REP(i,two) REP(j,two) REP(k,two){
	tmp[i][j] += mul(a[i][k], b[k][j]);
	if(tmp[i][j] >= MOD)
	  tmp[i][j] -= MOD;
  }
  return tmp;
}

LL solve(LL n){
  VVL xs = {{one,one},{one,zero}};
  VVL p = {{one,zero},{zero,one}};
  while(n > zero){
	if(n&one){
	  p = mul(p, xs);
	}

	xs = mul(xs, xs);
	n >>= one;
  }

  return mod(p[one][zero]+(p[one][one]<<one));
}

int main(){
  ++one;
  two = one;
  ++two;
  three = two;
  ++three;
  four = three;
  ++four;
  five = four;
  ++five;
  six = five;
  ++six;
  seven = six;
  ++seven;
  eight = seven;
  ++eight;
  nine = eight;
  ++nine;
  ten = nine;
  ++ten;

  MOD = ten;
  MOD = multiplies<LL>()(MOD, MOD);
  MOD = multiplies<LL>()(MOD, MOD);
  MOD = multiplies<LL>()(MOD, MOD);
  MOD = multiplies<LL>()(MOD, ten) + seven;
  
  int T;
  cin >> T;

  while(T--){
	LL n;
	cin >> n;
	cout << solve(n) << endl;
  }
}
0