結果
問題 | No.1653 Squarefree |
ユーザー | eQe |
提出日時 | 2024-10-31 23:10:34 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 4,764 bytes |
コンパイル時間 | 5,839 ms |
コンパイル使用メモリ | 316,440 KB |
実行使用メモリ | 814,564 KB |
最終ジャッジ日時 | 2024-10-31 23:10:45 |
合計ジャッジ時間 | 10,755 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 223 ms
16,660 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 2 ms
6,820 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 109 ms
14,996 KB |
testcase_12 | AC | 107 ms
14,932 KB |
testcase_13 | AC | 181 ms
16,692 KB |
testcase_14 | AC | 188 ms
16,652 KB |
testcase_15 | AC | 187 ms
16,584 KB |
testcase_16 | AC | 219 ms
16,664 KB |
testcase_17 | AC | 183 ms
16,596 KB |
testcase_18 | AC | 181 ms
16,608 KB |
testcase_19 | AC | 186 ms
16,500 KB |
testcase_20 | MLE | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> namespace my{ using namespace std; #define eb emplace_back #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define FO(n) for(ll 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 of(i,...) for(auto[i,i##stop,i##step]=range(1,__VA_ARGS__);i>=i##stop;i-=i##step) #define fe(a,i,...) for(auto&&__VA_OPT__([)i __VA_OPT__(,__VA_ARGS__]):a) #define single_testcase void solve();}int main(){my::io();my::solve();}namespace my{ void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);} using ll=long long; using ull=unsigned long long; using ulll=__uint128_t; using lll=__int128_t; istream&operator>>(istream&i,ulll&x){ull t;i>>t;x=t;return i;} ostream&operator<<(ostream&o,const ulll&x){return(x<10?o:o<<x/10)<<ll(x%10);} istream&operator>>(istream&i,lll&x){ll t;i>>t;x=t;return i;} ostream&operator<<(ostream&o,const lll&x){return o<<string(x<0,'-')<<ulll(x>0?x:-x);} auto range(bool s,ll a,ll b=1e18,ll c=1){if(b==1e18)b=a,(s?b:a)=0;return array{a-s,b,c};} constexpr char nl=10; constexpr char sp=32; constexpr auto square(auto x){return x*x;} auto ceil(auto x,auto y){if(y<0)x=-x,y=-y;return x<=0?x/y:(x-1)/y+1;} template<class A,class B>struct pair{ A a;B b; pair()=default; pair(A a,B b):a(a),b(b){} pair(const std::pair<A,B>&p):a(p.first),b(p.second){} auto operator<=>(const pair&)const=default; friend ostream&operator<<(ostream&o,const pair&p){return o<<p.a<<sp<<p.b;} }; 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 std::pair<T,U>&p){return o<<p.first<<sp<<p.second;} template<class V>concept vectorial=is_base_of_v<vector<typename V::value_type>,V>; template<class T>struct core_type{using type=T;}; template<vectorial V>struct core_type<V>{using type=typename core_type<typename V::value_type>::type;}; template<class T>using core_t=core_type<T>::type; 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(),vectorial<V>?nl:sp);return o;} template<class V>struct vec:vector<V>{ using vector<V>::vector; vec(const vector<V>&v){vector<V>::operator=(v);} vec&operator^=(const vec&u){this->insert(this->end(),u.begin(),u.end());return*this;} 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;} auto scan(const auto&f)const{pair<core_t<V>,bool>r{};fe(*this,e)if constexpr(!vectorial<V>)r.b?f(r.a,e),r:r={e,1};else if(auto s=e.scan(f);s.b)r.b?f(r.a,s.a),r:r=s;return r;} auto sum()const{return scan([](auto&a,const auto&b){a+=b;}).a;} }; template<bool is_negative=false>struct infinity{ template<integral T>constexpr operator T()const{return numeric_limits<T>::max()*(1-is_negative*2);} template<floating_point T>constexpr operator T()const{return static_cast<ll>(*this);} constexpr operator lll()const{return static_cast<ll>(*this);} template<class T>constexpr bool operator==(T x)const{return static_cast<T>(*this)==x;} constexpr auto operator-()const{return infinity<!is_negative>();} }; constexpr infinity oo; 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;} auto seq(ll l,ll r=oo){if(r==oo)r=l,l=0;vec<ll>a;fo(i,l,r)a.eb(i);return a;} uint64_t kth_root_floor(uint64_t a,ll k){ if (k==1)return a; auto is_within=[&](uint32_t x){uint64_t t=1;fo(k)if(__builtin_mul_overflow(t,x,&t))return false;return t<=a;}; uint64_t r=0; of(i,sizeof(uint32_t)*CHAR_BIT)if(is_within(r|(1u<<i)))r|=1u<<i; return r; } auto sqrt_floor(auto x){return kth_root_floor(x,2);} auto cbrt_floor(auto x){return kth_root_floor(x,3);} 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<(ll)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; } single_testcase void solve(){ LL(L,R); auto v=seq(L,R+1); vec<int>is_squarefree(R-L+1,1); fe(prime_enumerate(cbrt_floor(R)),p){ fo(X,ceil(L,p)*p,R/p*p+1,p){ if((X/p)%p==0)is_squarefree[X-L]=0; else v[X-L]/=p; } } fo(X,L,R+1){ if(!is_squarefree[X-L])continue; lll t=v[X-L]; if(t==1)continue; if(square(sqrt_floor(t))==t)is_squarefree[X-L]=0; } pp(is_squarefree.sum()); }}