結果
問題 |
No.3089 Base M Numbers, But Only 0~9
|
ユーザー |
![]() |
提出日時 | 2025-04-04 22:52:52 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 3,221 bytes |
コンパイル時間 | 4,237 ms |
コンパイル使用メモリ | 278,864 KB |
実行使用メモリ | 7,720 KB |
最終ジャッジ日時 | 2025-04-04 22:53:08 |
合計ジャッジ時間 | 4,976 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> #define ALL(x) (x).begin(), (x).end() #define LB(v, x) (int)(lower_bound(ALL(v), x) - (v).begin()) #define UQ(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end()) #define IO ios::sync_with_stdio(false), cin.tie(nullptr); #define chmax(a, b) (a) = (a) < (b) ? (b) : (a) #define chmin(a, b) (a) = (a) < (b) ? (a) : (b) using namespace std; using ll = long long; const int INF = 1e9 + 10; const ll INFL = 4e18; /// @file modint.hpp /// @brief ModInt template <ll MOD> struct ModInt { ModInt(ll x = 0) { value = (x >= 0 ? x % MOD : MOD - (-x) % MOD); } ModInt operator-() const { return ModInt(-value); } ModInt operator+() const { return ModInt(*this); } ModInt& operator+=(const ModInt& other) { value += other.value; if (value >= MOD) value -= MOD; return *this; } ModInt& operator-=(const ModInt& other) { value += MOD - other.value; if (value >= MOD) value -= MOD; return *this; } ModInt& operator*=(const ModInt other) { value = value * other.value % MOD; return *this; } ModInt& operator/=(ModInt other) { (*this) *= other.inv(); return *this; } ModInt operator+(const ModInt& other) const { return ModInt(*this) += other; } ModInt operator-(const ModInt& other) const { return ModInt(*this) -= other; } ModInt operator*(const ModInt& other) const { return ModInt(*this) *= other; } ModInt operator/(const ModInt& other) const { return ModInt(*this) /= other; } ModInt pow(ll x) const { ModInt ret(1), mul(value); while (x) { if (x & 1) ret *= mul; mul *= mul; x >>= 1; } return ret; } ModInt inv() const { return pow(MOD - 2); } bool operator==(const ModInt& other) const { return value == other.value; } bool operator!=(const ModInt& other) const { return value != other.value; } friend ostream& operator<<(ostream& os, const ModInt& x) { return os << x.value; } friend istream& operator>>(istream& is, ModInt& x) { ll v; is >> v; x = ModInt<MOD>(v); return is; } ll val() { return value; } static constexpr ll get_mod() { return MOD; } private: ll value; }; using Mod998 = ModInt<998244353>; using Mod107 = ModInt<1000000007>; using mint = Mod998; int main() { ll M; string S; cin >> M >> S; int N = ssize(S); vector<mint> patan(N); mint all = 1; for (int i = 0; i < N; i++) { ll cnt = M / 10 + (M % 10 > (S[i] - '0')); if (i == 0 && S[i] == '0') cnt--; patan[i] = cnt; all *= cnt; } mint ans = 0, minv = mint(2).inv(); for (int i = 0; i < N; i++) { // 0~patan[i]-1 if (i == 0 && S[i] == '0') { mint add = mint(S[i] - '0') * patan[i]; add += patan[i] * (patan[i] + 1) * minv * 10; ans += add * mint(M).pow(N - i - 1) * (all / patan[i]); } else { mint add = mint(S[i] - '0') * patan[i]; add += patan[i] * (patan[i] - 1) * minv * 10; ans += add * mint(M).pow(N - i - 1) * (all / patan[i]); } } cout << ans << endl; }