結果
問題 | No.1918 Simple Math ? |
ユーザー | eQe |
提出日時 | 2024-08-28 05:19:39 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,463 bytes |
コンパイル時間 | 6,883 ms |
コンパイル使用メモリ | 319,976 KB |
実行使用メモリ | 20,728 KB |
最終ジャッジ日時 | 2024-08-28 05:19:51 |
合計ジャッジ時間 | 10,329 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
15,944 KB |
testcase_01 | AC | 3 ms
6,944 KB |
testcase_02 | AC | 3 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 4 ms
6,940 KB |
testcase_05 | AC | 3 ms
6,940 KB |
testcase_06 | AC | 27 ms
15,732 KB |
testcase_07 | WA | - |
testcase_08 | AC | 23 ms
13,148 KB |
testcase_09 | AC | 13 ms
6,940 KB |
testcase_10 | WA | - |
testcase_11 | AC | 4 ms
6,940 KB |
testcase_12 | AC | 38 ms
14,072 KB |
testcase_13 | AC | 25 ms
15,136 KB |
testcase_14 | AC | 17 ms
9,756 KB |
testcase_15 | AC | 9 ms
6,944 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 143 ms
15,396 KB |
testcase_29 | AC | 2 ms
6,944 KB |
testcase_30 | AC | 2 ms
6,940 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> namespace my{ using namespace atcoder; using ml=modint1000000007; auto&operator<<(std::ostream&o,const ml&x){return o<<x.val();} auto&operator>>(std::istream&i,ml&x){long long t;i>>t;x=t;return i;} void main(); void solve(); } int main(){my::main();} namespace my{ #define eb emplace_back #define all(a) (a).begin(),(a).end() #define RD(T,...) T __VA_ARGS__;li(__VA_ARGS__) #define LL(...) RD(ll,__VA_ARGS__) #define JO(a,b) a##b #define jo(a,b) JO(a,b) #define FE(v,e,...) for(au&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):v) #define FO(n) for(ll jo(i,__LINE__)=n;jo(i,__LINE__)-->0;) #define FOR(i,...) for(au[i,i##O,i##E]=range(0,__VA_ARGS__);i<i##O;i+=i##E) #define fe(v,...) FE(v,__VA_ARGS__) #define fo(i,...) FO##__VA_OPT__(R)(i __VA_OPT__(,__VA_ARGS__)) #define of(i,...) for(au[i,i##O,i##E]=range(1,__VA_ARGS__);i>=i##O;i-=i##E) #define I template #define J class #define au auto #define rr return using namespace std; I<J A,J B>constexpr bool same=is_same_v<A,B>; using is=istream;using os=ostream;using dd=long double;using str=string; using ll=long long;using ull=unsigned long long;using lll=__int128_t;using ulll=__uint128_t; os&operator<<(os&o,const ulll&x){rr(x<10?o:o<<x/10)<<ll(x%10);} os&operator<<(os&o,const lll&x){rr o<<str(x<0,'-')<<ulll(x>0?x:-x);} constexpr dd ee=1e-12; constexpr ll oo=3e18; constexpr ll dx[]{-1,0,1,0,-1,1,1,-1},dy[]{0,-1,0,1,-1,-1,1,1}; constexpr char sp=32,nl=10; au Yes(bool y){rr y?"Yes":"No";} au No(){rr Yes(0);} au range(bool s,ll a,ll b=oo,ll c=1){if(b==oo)b=a,(s?b:a)=0;rr tuple{a-s,b,c};} I<J T>T zz(T x){rr x<0?-x:x;} I<J T>ll len(const T&a){rr a.size();} I<J A,J B=A>struct cp{ A a={};B b={}; cp(){} cp(A a,B b):a(a),b(b){} cp(pair<A,B>p):a(p.first),b(p.second){} bool operator==(const cp&c)const{rr a==c.a&&b==c.b;} auto operator<=>(const cp&c)const{rr a!=c.a?a<=>c.a:b<=>c.b;} friend is&operator>>(is&i,cp&c){rr i>>c.a>>c.b;} friend os&operator<<(os&o,const cp&c){rr o<<c.a<<sp<<c.b;} };using cl=cp<ll>; I<J A,J B=A,J C=A>struct tr{ A a={};B b={};C c={}; tr(){} tr(A a,B b,C c):a(a),b(b),c(c){} bool operator==(const tr&t)const{rr a==t.a&&b==t.b&&c==t.c;} auto operator<=>(const tr&t)const{rr a!=t.a?a<=>t.a:b!=t.b?b<=>t.b:c<=>t.c;} friend is&operator>>(is&i,tr&t){rr i>>t.a>>t.b>>t.c;} friend os&operator<<(os&o,const tr&t){rr o<<t.a<<sp<<t.b<<sp<<t.c;} };using tl=tr<ll>; I<J T>decltype(au)first(T&a){rr*begin(a);} I<J T>au pop_front(T&a){assert(len(a));au r=first(a);a.pop_front();rr r;} I<J T,size_t n>using array=std::array<T,n>; I<J T,size_t n>os&operator<<(os&o,const array<T,n>&a){fo(i,n)o<<a[i]<<str(i!=n-1,sp);rr o;} I<J T,J U=T>using map=std::map<T,U>; I<J T,J U>os&operator<<(os&o,const map<T,U>&m){fe(m,e)o<<e.first<<sp<<e.second<<nl;rr o;} I<J T,J U=T>using umap=unordered_map<T,U>; I<J T,J U>os&operator<<(os&o,const umap<T,U>&m){fe(m,e)o<<e.first<<sp<<e.second<<nl;rr o;} I<size_t n>using bset=bitset<n>; I<size_t n>os&operator<<(os&o,const bset<n>&b){fo(i,n)o<<b[i];rr o;} I<J...A>os&operator<<(os&o,const tuple<A...>&t){apply([&](const au&...a){ll i=sizeof...(a);(((o<<a<<str(--i>0,sp))),...);},t);rr o;} I<J T,J F>struct priority_queue:std::priority_queue<T,vector<T>,F>{ priority_queue(const initializer_list<T>&a={}){fe(a,e)this->emplace(e);} priority_queue(const vector<T>&a){fe(a,e)this->emplace(e);} T front(){rr this->top();} T pop_front(){T r=this->top();this->pop();rr r;} friend os&operator<<(os&o,priority_queue q){while(len(q))o<<q.pop_front()<<str(len(q)>0,sp);rr o;} }; I<J T>using max_priority_queue=priority_queue<T,less<>>; I<J T>using min_priority_queue=priority_queue<T,greater<>>; I<J V>struct ve; I<J V>constexpr bool isv=0; I<J V>constexpr bool isv<ve<V>> =1; I<J V>constexpr bool isv<vector<V>> =1; I<J V>au rawv(V){if constexpr(isv<V>)rr rawv(V(1)[0]);else rr V();} I<J V>struct ve:vector<V>{ using vector<V>::vector; using T=decltype(rawv(V())); I<J U>ve(const vector<U>&v={}){static_assert(isv<V> ==isv<U>);fe(v,e)this->eb(e);} ve&operator+=(const ve&u){au&v=*this;fo(i,len(v))v[i]+=u[i];rr v;}ve operator+(const ve&u)const{rr ve(*this)+=u;} ve&operator-=(const ve&u){au&v=*this;fo(i,len(v))v[i]-=u[i];rr v;}ve operator-(const ve&u)const{rr ve(*this)-=u;} ve&operator^=(const ve&u){fe(u,e)this->eb(e);rr*this;}ve operator^(const ve&u)const{rr ve(*this)^=u;} ve&operator+=(const T&x){au&v=*this;fe(v,e)e+=x;rr v;}ve operator+(const T&x)const{rr ve(*this)+=x;} ve&operator-=(const T&x){au&v=*this;fe(v,e)e-=x;rr v;}ve operator-(const T&x)const{rr ve(*this)-=x;} ve&operator*=(const T&x){au&v=*this;fe(v,e)e*=x;rr v;}ve operator*(const T&x)const{rr ve(*this)*=x;} ve&operator++(){rr*this+=1;} ve&operator--(){rr*this-=1;} ve operator-()const{rr ve(*this)*=-1;} I<size_t n>au&operator+=(const bset<n>&a){fo(i,n)(*this)[i]+=a[i];rr*this;} I<size_t n>au&operator-=(const bset<n>&a){fo(i,n)(*this)[i]-=a[i];rr*this;} au lower_bound(const V&x)const{rr std::lower_bound(all(*this),x);} au upper_bound(const V&x)const{rr std::upper_bound(all(*this),x);} ve zeta()const{ve v=*this;if constexpr(isv<V>)fe(v,e)e=e.zeta();fo(i,len(v)-1)v[i+1]+=v[i];rr v;} void af(const V&x={}){this->emplace(this->begin(),x);} friend is&operator>>(is&i,ve&v){fe(v,e)i>>e;rr i;} friend os&operator<<(os&o,const ve&v){fe(v,e)o<<e<<str(&e!=&v.back(),isv<V>?nl:sp);rr o;} }; I<J T=ll,size_t n,size_t i=0>au vec(const ll(&s)[n],T x={}){if constexpr(n==i+1)rr ve<T>(s[i],x);else{au X=vec<T,n,i+1>(s,x);rr ve<decltype(X)>(s[i],X);}} I<ll n,J...A>void setsize(const ll(&l)[n],A&...a){((a=vec(l,rawv(a))),...);} I<J T>using v2=ve<ve<T>>;using u1=ve<ll>;using u2=v2<ll>; using graph=v2<cl>; void io(){cin.tie(0)->sync_with_stdio(0);cout<<fixed<<setprecision(15);cerr<<nl;} I<J...A>void li(A&...a){(cin>>...>>a);} I<char c=sp,J...A>void pp(const A&...a){ll i=sizeof...(a);((cout<<a<<str(--i>0,c)),...);cout<<nl;} ll floor_sqrt(ll x){ll r=sqrt(zz(x-ee));while(r+1<=x/(r+1))++r;rr r;} I<J F>struct rec:F{rec(F&&f):F(std::forward<F>(f)){}I<J...A>decltype(au)operator()(A&&...a)const{rr F::operator()(*this,std::forward<A>(a)...);}}; template<class T>T loop_sum(const ve<T>&a,ll k){ ll n=len(a); ve<T>s=a.zeta();s.af(); T r=k/n*s.back()+s[k%n]; return r; } void main(){io();ll T=1;li(T);fo(T)solve();} void solve(){ LL(A,N); ll M=floor_sqrt(A*N); ve<ml>v; fo(j,1,A+1)v.eb((j*j-1)%A); ml S=ml(M)*(M+1)*(M*2+1)/6-M-loop_sum(v,M); pp(N*M-S/A); }}