結果
問題 | No.3036 Restricted Lucas (Easy) |
ユーザー | okaduki |
提出日時 | 2018-04-01 23:23:28 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,783 bytes |
コンパイル時間 | 853 ms |
コンパイル使用メモリ | 80,548 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 06:07:11 |
合計ジャッジ時間 | 1,349 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 3 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
ソースコード
#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; } }