結果
問題 | No.2649 [Cherry 6th Tune C] Anthem Flower |
ユーザー |
![]() |
提出日時 | 2024-02-23 21:37:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 636 ms / 2,000 ms |
コード長 | 2,925 bytes |
コンパイル時間 | 2,062 ms |
コンパイル使用メモリ | 192,912 KB |
最終ジャッジ日時 | 2025-02-19 19:33:48 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
#include <bits/stdc++.h>#ifdef LOCAL#include "./debug.cpp"#else#define debug(...)#define print_line#endifusing namespace std;using ll = long long;struct dynamic_modint {long long value;static long long mod;static void set_mod(long long x) {mod = x;}static long long get_mod() {return mod;}dynamic_modint(long long x = 0) {if (x >= 0) {value = x % mod;} else {value = mod - (-x) % mod;}}dynamic_modint operator-() const {return dynamic_modint(-value);}dynamic_modint operator+() const {return dynamic_modint(*this);}dynamic_modint &operator+=(const dynamic_modint &other) {value += other.value;if (value >= mod) value -= mod;return *this;}dynamic_modint &operator-=(const dynamic_modint &other) {value += mod - other.value;if (value >= mod) value -= mod;return *this;}dynamic_modint &operator*=(const dynamic_modint other) {value = value * other.value % mod;return *this;}dynamic_modint &operator/=(dynamic_modint other) {(*this) *= other.inv();return *this;}dynamic_modint operator+(const dynamic_modint &other) const {return dynamic_modint(*this) += other;}dynamic_modint operator-(const dynamic_modint &other) const {return dynamic_modint(*this) -= other;}dynamic_modint operator*(const dynamic_modint &other) const {return dynamic_modint(*this) *= other;}dynamic_modint operator/(const dynamic_modint &other) const {return dynamic_modint(*this) /= other;}dynamic_modint pow(long long x) const {dynamic_modint ret(1), mul(value);while (x) {if (x & 1) ret *= mul;mul *= mul;x >>= 1;}return ret;}dynamic_modint inv() const {return pow(mod - 2);}bool operator==(const dynamic_modint &other) const {return value == other.value;}bool operator!=(const dynamic_modint &other) const {return value != other.value;}friend ostream &operator<<(ostream &os, const dynamic_modint &x) {return os << x.value;}friend istream &operator>>(istream &is, dynamic_modint &x) {long long v;is >> v;x = dynamic_modint(v);return is;}};long long dynamic_modint::mod = 998244353;using mint = dynamic_modint;int main() {int T;cin >> T;while (T--) {string N;int M;cin >> N >> M;mint::set_mod(2 * M);mint n = 0, tmp = 1;for (int i = (int)N.size() - 1; i >= 0; i--) {n += tmp * (N[i] - '0');tmp *= 10;}n *= n + 1;cout << n.value / 2 % M << '\n';}}