結果
問題 |
No.1022 Power Equation
|
ユーザー |
|
提出日時 | 2025-08-29 04:49:26 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 12 ms / 2,000 ms |
コード長 | 2,054 bytes |
コンパイル時間 | 3,562 ms |
コンパイル使用メモリ | 278,180 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-08-29 04:49:31 |
合計ジャッジ時間 | 4,064 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
ソースコード
#include<bits/stdc++.h> #if __has_include(<atcoder/all>) #endif using namespace std; #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define FO(n) for(ll IJK=n;IJK-->0;) #define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step) #define of(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(1,__VA_ARGS__);i>=i##stop;i+=i##step) #define defpp template<ostream&o=cout>void pp(const auto&...a){[[maybe_unused]]const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}void epp(const auto&...a){pp<cerr>(a...);} #define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{ #define multiple_testcases LL(T);FO(T)main2();}void main2(){ namespace my{ void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);} using ll=long long; using ui32=uint32_t; using ui64=uint64_t; template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};} template<class T>constexpr auto for_range(T s,T a,T b,T c=1){return array{a-s,b,(1-s*2)*c};} void lin(auto&...a){(cin>>...>>a);} constexpr auto abs(auto x){return x<0?-x:x;} constexpr ll size2(auto x){x|=1;ll r=0;while(x>0)x>>=1,++r;return r;} constexpr ll log2_floor(auto x){return size2(x)-1;} auto floor(auto x,auto y){if(y<0)x=-x,y=-y;return x>=0?x/y:(x+1)/y-1;} auto max(auto...a){return max(initializer_list<common_type_t<decltype(a)...>>{a...});} template<class T,class U>common_type_t<T,U>gcd(T a,U b){return b?gcd(b,a%b):abs(a);} auto bot(auto...a){return gcd(a...)==1;} constexpr ui64 kth_root_floor(ui64 a,ll k){ if (k==1)return a; auto within=[&](ui32 x){ui64 t=1;FO(k)if(__builtin_mul_overflow(t,x,&t))return false;return t<=a;}; ui64 r=0; of(i,sizeof(ui32)*CHAR_BIT)if(within(r|(1u<<i)))r|=1u<<i; return r; } } namespace my{entry void main(){ multiple_testcases LL(N); ll M=log2_floor(N); ll ans=N*N; // a=c=1のとき // a,c>=2のとき fo(bb,1,M+1)fo(dd,1,M+1){ if(!bot(bb,dd))continue; ans+=(kth_root_floor(N,max(bb,dd))-1)*floor(N,max(bb,dd)); } pp(ans); }}