結果
問題 |
No.3089 Base M Numbers, But Only 0~9
|
ユーザー |
|
提出日時 | 2025-04-04 22:12:43 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 2,708 bytes |
コンパイル時間 | 4,182 ms |
コンパイル使用メモリ | 310,484 KB |
実行使用メモリ | 7,720 KB |
最終ジャッジ日時 | 2025-04-04 22:12:58 |
合計ジャッジ時間 | 5,152 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 19 |
ソースコード
#pragma GCC optimize ("O3,inline,omit-frame-pointer,no-asynchronous-unwind-tables,fast-math") #include <bits/stdc++.h> #include <unordered_map> #include <stdlib.h> using namespace std; #define rep(i, a, n) for(ll i = a; i < n; i++) #define rrep(i, a, n) for(ll i = a; i >= n; i--) #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> //constexpr ll MOD = 1000000007; constexpr ll MOD = 998244353; constexpr int IINF = 1001001001; constexpr ll INF = 1LL<<60; template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;} template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;} template<int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) { } ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; }; template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } typedef ModInt<998244353> mint; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); ll m; cin >> m; string n; cin >> n; mint ans = 0, num = 1; ll flg = 1; for(auto c: n){ ans *= (m%MOD); ll x = (m/10)+ (m%10 > (c-'0') ? 1: 0); if(flg && c == '0') x--; ans *= (x%MOD); if(flg && c == '0') ans += num*((5+x*5)%MOD)*(x%MOD); else ans += num*((((x-1)*5)%MOD)*(x%MOD) + ((c-'0')*x)%MOD); num *= (x%MOD); flg = 0; } cout << ans << endl; return 0; }