提出 #67785025


ソースコード 拡げる

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int p=998244353;
int po(int a,int b) {if(b==0) return 1; if(b==1) return a; if(b%2==0) {int u=po(a,b/2);return (u*1LL*u)%p;} else {int u=po(a,b-1);return (a*1LL*u)%p;}}
int inv(int x) {return po(x,p-2);}
mt19937 rnd;
#define app push_back
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(...) [](auto...a){ ((cout << a << ' '), ...) << endl;}(#__VA_ARGS__, ":", __VA_ARGS__)
#define debugv(v) do {cout<< #v <<" : {"; for(int izxc=0;izxc<v.size();++izxc) {cout << v[izxc];if(izxc+1!=v.size()) cout << ","; }cout <<"}"<< endl;} while(0)
#else
#define debug(...)
#define debugv(v)
#endif
#define lob(a,x) lower_bound(all(a),x)
#define upb(a,x) upper_bound(all(a),x)
#define print(x) cout<<(x)<<'\n'
#define suma(a) accumulate(all(a),0LL)
#define maxpos(a) max_element(all(a))-a.begin()
#define minpos(a) min_element(all(a))-a.begin()
#define maxa(a) *max_element(all(a))
#define mina(a) *min_element(all(a))
pair<int,vector<int> > read()
{
    int n;cin>>n;vector<int> a(n);for(int &x:a) {cin>>x;} return {n,a};
}
const int maxn=2e5+5;
int cnt[maxn];int cnt2[maxn];vector<int> di[maxn];int mu[maxn];
int H[maxn];int invH[maxn];
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    for(int i=0;i<maxn;++i) {
        H[i]=po(10,i)-1;invH[i]=inv(H[i]);
    }
    for(int i=1;i<maxn;++i) for(int j=i;j<maxn;j+=i) di[j].app(i);
    for(int i=1;i<maxn;++i) {
        if(i==1) {mu[i]=1;continue;}
        int p=di[i][1];
        if(i%(p*p)==0) {mu[i]=0;}
        else {mu[i]=mu[i/p]*(-1);}
    }
    int n;cin>>n;
    /*for(int d=1;d<maxn;++d) {
        int s=0;
        for(int i=d;i<maxn;i+=d) {s+=cnt[i];}
        if(s==0) {cnt2[d]=0;}
        else if(s%2==1) {cnt2[d]=1;}
        else {cnt2[d]=1;}
    }
    int res=1;
    for(int d=maxn-1;d>=1;--d) {
        for(int i=2*d;i<maxn;i+=d) {cnt2[d]-=cnt2[i];}
        int h=po(10,d)-1;h%=p;int ih=inv(h);
        if(cnt2[d]) {debug(d,cnt2[d],h);}
        if(cnt2[d]<0) {
            res*=po(ih,-cnt2[d]);res%=p;
        }
        else if(cnt2[d]>0) {
            res*=po(h,cnt2[d]);res%=p;
        }
    }
    res*=inv(9);res%=p;
    cout<<(res%p+p)%p;*/
    int res=1;
    int i9=inv(9);
    for(int i=0;i<n;++i) {int x;cin>>x;if(!cnt[x]) {cnt[x]=1;
    for(int d:di[x]) {
        if(!cnt2[d]) {
            cnt2[d]=1;
            for(int y:di[d]) {
                if(mu[d/y]==1) {
                    res*=H[y];res%=p;
                }
                else if(mu[d/y]==(-1)) {
                    res*=invH[y];res%=p;
                }
            }
        }
    }
    }
    cout<<((res*i9)%p+p)%p<<'\n';
    }
    return 0;
}

提出情報

提出日時
問題 C - Repunits
ユーザ turmax
言語 C++ 20 (gcc 12.2)
得点 900
コード長 2780 Byte
結果 AC
実行時間 309 ms
メモリ 44472 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 900 / 900
結果
AC × 3
AC × 30
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_n_small_00.txt, 01_n_small_01.txt, 01_n_small_02.txt, 01_n_small_03.txt, 01_n_small_04.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 03_hcn_00.txt, 03_hcn_01.txt, 03_hcn_02.txt, 03_hcn_03.txt, 03_hcn_04.txt, 04_max_00.txt, 05_min_00.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 195 ms 41288 KiB
00_sample_01.txt AC 199 ms 41356 KiB
00_sample_02.txt AC 201 ms 41340 KiB
01_n_small_00.txt AC 206 ms 44420 KiB
01_n_small_01.txt AC 205 ms 43964 KiB
01_n_small_02.txt AC 187 ms 44104 KiB
01_n_small_03.txt AC 200 ms 44220 KiB
01_n_small_04.txt AC 189 ms 44300 KiB
02_random_00.txt AC 249 ms 44424 KiB
02_random_01.txt AC 259 ms 44364 KiB
02_random_02.txt AC 267 ms 44392 KiB
02_random_03.txt AC 260 ms 44412 KiB
02_random_04.txt AC 289 ms 44328 KiB
02_random_05.txt AC 289 ms 44460 KiB
02_random_06.txt AC 284 ms 44384 KiB
02_random_07.txt AC 273 ms 44340 KiB
02_random_08.txt AC 237 ms 44272 KiB
02_random_09.txt AC 259 ms 44340 KiB
02_random_10.txt AC 248 ms 44472 KiB
02_random_11.txt AC 306 ms 44408 KiB
02_random_12.txt AC 295 ms 44412 KiB
02_random_13.txt AC 309 ms 44424 KiB
02_random_14.txt AC 309 ms 44412 KiB
03_hcn_00.txt AC 233 ms 44420 KiB
03_hcn_01.txt AC 228 ms 44332 KiB
03_hcn_02.txt AC 218 ms 44464 KiB
03_hcn_03.txt AC 220 ms 44324 KiB
03_hcn_04.txt AC 218 ms 44344 KiB
04_max_00.txt AC 212 ms 41284 KiB
05_min_00.txt AC 196 ms 41292 KiB