結果

問題 No.3037 Restricted Lucas (Hard)
ユーザー okadukiokaduki
提出日時 2018-04-02 00:25:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,920 bytes
コンパイル時間 842 ms
コンパイル使用メモリ 81,908 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 13:10:07
合計ジャッジ時間 1,498 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <functional>
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=plus<LL>()(i,one))
#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] = plus<LL>()(tmp[i][j], mul(a[i][k], b[k][j]));
	tmp[i][j] = mod(tmp[i][j]);
  }
  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(plus<LL>()(p[one][zero],(p[one][one]<<one)));
}

int main(){
  one = !!M_PI;
  two = plus<LL>()(one, one);
  three = plus<LL>()(two, one);
  four = plus<LL>()(three, one);
  five = plus<LL>()(four, one);
  six = plus<LL>()(five, one);
  seven = plus<LL>()(six, one);
  eight = plus<LL>()(seven, one);
  nine = plus<LL>()(eight, one);
  ten = plus<LL>()(nine, one);

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

  REP(t,T){
	LL n;
	cin >> n;
	cout << solve(n) << endl;
  }
}
0