結果
| 問題 | 
                            No.8037 Restricted Lucas (Hard)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             okaduki
                         | 
                    
| 提出日時 | 2018-04-02 00:25:27 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 1,920 bytes | 
| コンパイル時間 | 926 ms | 
| コンパイル使用メモリ | 83,032 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-26 06:22:30 | 
| 合計ジャッジ時間 | 1,479 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 6 | 
ソースコード
#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;
  }
}
            
            
            
        
            
okaduki