結果
問題 | No.2902 ZERO!! |
ユーザー |
|
提出日時 | 2024-09-29 13:47:42 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 279 ms / 2,000 ms |
コード長 | 3,619 bytes |
コンパイル時間 | 5,847 ms |
コンパイル使用メモリ | 326,848 KB |
実行使用メモリ | 12,532 KB |
最終ジャッジ日時 | 2024-09-29 13:47:57 |
合計ジャッジ時間 | 9,778 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> namespace my{ using ml=atcoder::modint998244353; auto&operator>>(std::istream&i,ml&x){int t;i>>t;x=t;return i;} auto&operator<<(std::ostream&o,const ml&x){return o<<x.val();} void main(); void solve(); } int main(){my::main();} namespace my{ #define eb emplace_back #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define FO(n) for(ll ij=0;ij<n;++ij) #define FOR(i,...) for(auto[i,i##stop,i##step]=range(0,__VA_ARGS__);i<i##stop;i+=i##step) #define fo(i,...) FO##__VA_OPT__(R)(i __VA_OPT__(,__VA_ARGS__)) #define fe(a,i,...) for(auto&&__VA_OPT__([)i __VA_OPT__(,__VA_ARGS__]):a) using namespace std; using dd=long double; using ll=long long; constexpr dd ee=1e-12; constexpr char nl=10; constexpr char sp=32; auto range(bool s,ll a,ll b=9e18,ll c=1){if(b==9e18)b=a,(s?b:a)=0;return tuple{a-s,b,c};} auto zz(auto x){return x<0?-x:x;} ll sqrt_floor(ll x){ll r=sqrt(zz(x-ee));while(r+1<=x/(r+1))++r;return r;} bool amax(auto&a,const auto&b){return a<b?a=b,1:0;} auto pop_back(auto&a){assert(a.size());auto r=*a.rbegin();a.pop_back();return r;} template<class T,class U>ostream&operator<<(ostream&o,const map<T,U>&m){fe(m,e)o<<e.first<<sp<<e.second<<nl;return o;} template<class T,class U>ostream&operator<<(ostream&o,const unordered_map<T,U>&m){fe(m,e)o<<e.first<<sp<<e.second<<nl;return o;} template<size_t n>ostream&operator<<(ostream&o,const bitset<n>&b){fo(i,n)o<<b[i];return o;} template<class V>concept isv=is_base_of_v<vector<typename V::value_type>,V>; template<class V>istream&operator>>(istream&i,vector<V>&v){fe(v,e)i>>e;return i;} template<class V>ostream&operator<<(ostream&o,const vector<V>&v){fe(v,e)o<<e<<string(&e!=&v.back(),isv<V>?nl:sp);return o;} template<class V>struct vec:vector<V>{ using vector<V>::vector; vec(const vector<V>&v){fe(v,e)this->eb(e);} template<size_t n>vec(const bitset<n>&a){fo(i,n)this->eb(a[i]);} vec&operator+=(const vec&u){vec&v=*this;fo(i,v.size())v[i]+=u[i];return v;} vec&operator-=(const vec&u){vec&v=*this;fo(i,v.size())v[i]-=u[i];return v;} vec&operator^=(const vec&u){fe(u,e)this->eb(e);return*this;} vec operator+(const vec&u)const{return vec(*this)+=u;} vec operator-(const vec&u)const{return vec(*this)-=u;} vec operator^(const vec&u)const{return vec(*this)^=u;} vec&operator++(){fe(*this,e)++e;return*this;} vec&operator--(){fe(*this,e)--e;return*this;} vec operator-()const{vec v=*this;fe(v,e)e=-e;return v;} }; void io(){cin.tie(0)->sync_with_stdio(0);cout<<fixed<<setprecision(15);cerr<<nl;} void lin(auto&...a){(cin>>...>>a);} template<char c=sp>void pp(const auto&...a){ll n=sizeof...(a);((cout<<a<<string(--n>0,c)),...);cout<<nl;} vec<ll>prime_enumerate(ll n){ vec<bool>sieve(n/3+1,1); for(ll p=5,d=4,i=1,rn=sqrt_floor(n);p<=rn;p+=d=6-d,i++){ if(!sieve[i])continue; for(ll q=(p*p)/3,r=d*p/3+(d*p%3==2),s=p*2;q<sieve.size();q+=r=s-r)sieve[q]=0; } vec<ll>r{2,3}; for(ll p=5,d=4,i=1;p<=n;p+=d=6-d,i++)if(sieve[i])r.eb(p); while(r.size()&&r.back()>n)r.pop_back(); return r; } auto legendre_formula(ll n){ auto primes=prime_enumerate(n); unordered_map<ll,ll>r; fe(primes,p)for(ll t=p;t<=n;t*=p)r[p]+=n/t; return map<ll,ll>(r.begin(),r.end()); } void main(){io();ll T=1;fo(T)solve();} void solve(){ LL(N); auto primes=prime_enumerate(N); auto factors=legendre_formula(N); ll B=0; fe(factors,p,b)amax(B,b); ml ans=0; fo(i,1,B+1){ ml t=1; fe(primes,p)t*=(1+factors[p]/i); ans+=t-1;//1は除外 ll cu=(ll)primes.size()-1; while(cu>=0&&factors[primes[cu]]/i==0){ primes.pop_back(); cu--; } } pp(ans); }}