結果
問題 | No.3036 Restricted Lucas (Easy) |
ユーザー | WarToks |
提出日時 | 2019-04-06 14:53:21 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 2,125 bytes |
コンパイル時間 | 628 ms |
コンパイル使用メモリ | 119,040 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 14:43:53 |
合計ジャッジ時間 | 1,358 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 6 ms
5,248 KB |
testcase_03 | AC | 7 ms
5,248 KB |
testcase_04 | AC | 6 ms
5,248 KB |
testcase_05 | AC | 6 ms
5,248 KB |
testcase_06 | AC | 6 ms
5,248 KB |
ソースコード
#include <iostream> using lli = long long int; constexpr int zero = false; constexpr lli zeroL = zero; constexpr int one = true; constexpr lli oneL = one; constexpr int two = one << one; constexpr int three = two + one; constexpr int four = two << one; constexpr int five = four + one; constexpr int eight = four << one; constexpr int seven = eight - one; constexpr int nine = eight + one; constexpr int fourteen = (eight - one) << one; constexpr int nineteen = (nine << one) + one; constexpr int twenty_three = nineteen + four; constexpr int sixty_four = (eight << three); constexpr int twoSeven_twoThree_one = (one << seven) - (one << three) - one; constexpr lli mod = seven + (five << nine) + ( (three + eight) << fourteen) + (three << nineteen) + (twoSeven_twoThree_one << twenty_three); lli mult(lli a, lli b){ lli bit = one, res = zero; for(int i = zero; i < sixty_four; i++){ if(bit & b) res += (a << i); bit <<= one; } return res; } lli div_q(lli a, lli b){ lli res = zero; while(a >= b){ int i = zero; while(a >= (b << (i + one))) i++; a -= (b << i); } return a; } void calcu(lli &a, lli &b, lli &c, int n){ if(n == zero){ a = oneL; b = zeroL; c = oneL; return; } lli aa = a, bb = b, cc = c; calcu(aa, bb, cc, n >> one); if((n & one) == zeroL){ a = div_q(mult(aa, aa) + mult(bb, bb), mod); b = div_q(mult(bb, aa + cc), mod); c = div_q(mult(bb, bb) + mult(cc, cc), mod); } else{ lli aaa = div_q(mult(aa, aa) + mult(bb, bb), mod), bbb = div_q(mult(bb, aa + cc), mod), ccc = div_q(mult(bb, bb) + mult(cc, cc), mod); aa = div_q(mult(aaa, a) + mult(bbb, b), mod); bb = div_q(mult(a, bbb) + mult(b, ccc), mod); cc = div_q(mult(b, bbb) + mult(c, ccc), mod); a = aa; b = bb; c = cc; } } int getAns(int n){ if(n == zero) return two; lli a = oneL, b = one, c = zero; calcu(a, b, c, n-one); return div_q(a + (b << one), mod); } int main(void){ int t, n; std::cin >> t; for(int i = zero; i < t; i++){ std::cin >> n; std::cout << getAns(n) << std::endl; } return zero; }