結果
問題 | No.1022 Power Equation |
ユーザー |
![]() |
提出日時 | 2020-04-10 22:37:18 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,615 ms / 2,000 ms |
コード長 | 1,078 bytes |
コンパイル時間 | 11,030 ms |
コンパイル使用メモリ | 258,432 KB |
最終ジャッジ日時 | 2025-01-09 16:23:04 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
ソースコード
#include <bits/stdc++.h> using namespace std; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} using Int = long long; const char newl = '\n'; //INSERT ABOVE HERE signed solve(){ Int n; cin>>n; Int ans=0; // a == c, a != 1, b == d ans+=(n-1)*n; // a == c == 1 ans+=n*n; // a != c // x^pb == x^qd // count (p, q) const Int LOG = 32; Int cnt[LOG][LOG]={}; set<Int> used; for(Int i=2;i*i<=n;i++){ if(used.count(i)) continue; Int k=0,po=1; while(po*i<=n){ po*=i; k++; used.emplace(po); } for(Int p=0;p<=k;p++) for(Int q=0;q<=k;q++) cnt[p][q]++; } auto calc=[&](Int p,Int q){ if(p>q) swap(p,q); Int l=lcm(p,q); return n/(l/p); }; for(Int p=1;p<LOG;p++) for(Int q=1;q<LOG;q++) if(p!=q) ans+=cnt[p][q]*calc(p,q); cout<<ans<<newl; return 0; } signed main(){ cin.tie(0); ios::sync_with_stdio(0); Int T; cin>>T; while(T--) solve(); return 0; }