結果
問題 | No.2600 Avator Height |
ユーザー | nono00 |
提出日時 | 2024-01-12 21:33:50 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 3,372 bytes |
コンパイル時間 | 3,034 ms |
コンパイル使用メモリ | 247,476 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-27 21:26:29 |
合計ジャッジ時間 | 7,074 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
6,812 KB |
testcase_01 | AC | 53 ms
6,940 KB |
testcase_02 | AC | 55 ms
6,940 KB |
testcase_03 | AC | 55 ms
6,940 KB |
testcase_04 | AC | 54 ms
6,940 KB |
testcase_05 | AC | 52 ms
6,944 KB |
testcase_06 | AC | 55 ms
6,940 KB |
testcase_07 | AC | 50 ms
6,940 KB |
testcase_08 | AC | 48 ms
6,940 KB |
testcase_09 | AC | 49 ms
6,944 KB |
testcase_10 | AC | 53 ms
6,944 KB |
testcase_11 | AC | 54 ms
6,940 KB |
testcase_12 | AC | 52 ms
6,944 KB |
testcase_13 | AC | 53 ms
6,940 KB |
testcase_14 | AC | 55 ms
6,940 KB |
testcase_15 | AC | 50 ms
6,940 KB |
testcase_16 | AC | 53 ms
6,940 KB |
testcase_17 | AC | 54 ms
6,940 KB |
testcase_18 | AC | 49 ms
6,944 KB |
testcase_19 | AC | 51 ms
6,948 KB |
testcase_20 | AC | 54 ms
6,944 KB |
testcase_21 | AC | 48 ms
6,940 KB |
testcase_22 | AC | 51 ms
6,940 KB |
testcase_23 | AC | 47 ms
6,940 KB |
testcase_24 | AC | 26 ms
6,940 KB |
testcase_25 | AC | 38 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> #include <iostream> namespace nono { namespace internal { constexpr bool is_prime(unsigned long long n) { for (unsigned long long i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } } // namespace internal template <unsigned long long MOD = 998244353> class Modint { public: static_assert(internal::is_prime(MOD)); constexpr Modint(unsigned long long value = 0): value_(value % MOD) {} constexpr Modint pow(long long exp) const { Modint result(1); Modint base(*this); while (exp > 0) { if (exp & 1) { result *= base; } base *= base; exp >>= 1; } return result; } constexpr Modint inv() const { return pow(MOD - 2); } void set(unsigned long long value) { if (value >= MOD) value %= MOD; value_ = value; } unsigned long long get() const { return value_; } friend constexpr bool operator==(const Modint lhs, const Modint rhs) { return lhs.value_ == rhs.value_; } constexpr Modint& operator+=(const Modint other) { this->value_ += other.value_; if (this->value_ >= MOD) this->value_ -= MOD; return *this; } constexpr Modint& operator-=(const Modint other) { this->value_ += MOD - other.value_; if (this->value_ >= MOD) this->value_ -= MOD; return *this; } constexpr Modint& operator*=(const Modint other) { this->value_ *= other.value_; if (this->value_ >= MOD) this->value_ %= MOD; return *this; } constexpr Modint& operator/=(const Modint other) { return *this *= other.inv(); } constexpr friend Modint operator+(const Modint lhs, const Modint rhs) { return Modint(lhs) += rhs; } constexpr friend Modint operator-(const Modint lhs, const Modint rhs) { return Modint(lhs) -= rhs; } constexpr friend Modint operator*(const Modint lhs, const Modint rhs) { return Modint(lhs) *= rhs; } constexpr friend Modint operator/(const Modint lhs, const Modint rhs) { return Modint(lhs) /= rhs; } friend std::istream& operator>>(std::istream& stream, Modint& mint) { unsigned long long value; stream >> value; mint.set(value); return stream; } friend std::ostream& operator<<(std::ostream& stream, Modint mint) { stream << mint.get(); return stream; } private: unsigned long long value_; }; using Modint998244353 = Modint<998244353>; using Modint1000000007 = Modint<1000000007>; } // namespace nono void solve() { using Mint = nono::Modint998244353; const int N = 200005; std::array<Mint, N> r, e; r.fill(1); e.fill(1); r[1] = 1; r[2] = 1; for (int i = 3; i < N; i++) { r[i] = r[i - 1] + r[i - 2]; } e[1] = 1; e[2] = 3; for (int i = 3; i < N; i++) { e[i] = e[i - 1] + e[i - 2]; } int q; std::cin >> q; while (q--) { int n; std::cin >> n; std::cout << 5 * r[n].pow(2) - e[n].pow(2) << '\n'; } } int main() { std::cin.tie(0)->sync_with_stdio(0); std::cout << std::fixed << std::setprecision(16); int t = 1; while (t--) solve(); }