結果

問題 No.3089 Base M Numbers, But Only 0~9
ユーザー askr58
提出日時 2025-04-04 22:57:30
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 909 bytes
コンパイル時間 6,631 ms
コンパイル使用メモリ 332,404 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2025-04-04 22:58:03
合計ジャッジ時間 7,179 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using mint=modint998244353;
int main()
{
    ll m;
    cin>>m;
    string s;
    cin>>s;
    int n=s.size();
    mint ss=1;
    int cnt=0;
    for(int i=0;i<n;i++){
        mint x=m/10;
        if((s[i]-'0')<m%10)x++;
        if(x.val()!=0)ss*=x;
        else cnt++;
    }
    if(cnt>1){
        cout<<0<<endl;
        return 0;
    }
    mint ans=0;
    mint t=1;
    reverse(s.begin(),s.end());
    for(int i=0;i<n;i++){
        mint x=m/10;
        if((s[i]-'0')<m%10)x++;
        if(i+1==n&&s[i]=='0'){
            if(x.val()!=0)ans=ans*(x-1)/x;
            
        }
        {
            if(cnt==0)ans+=ss/x*((s[i]-'0')*x+5*x*(x-1))*t;
            else if(cnt==1&&x.val()==0)ans+=ss*((s[i]-'0')*x+5*x*(x-1))*t;
        }
        t*=m;
    }
    cout<<ans.val()<<endl;
    
    return 0;
}
0