結果

問題 No.1022 Power Equation
ユーザー beetbeet
提出日時 2020-04-10 22:37:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 834 ms / 2,000 ms
コード長 1,078 bytes
コンパイル時間 2,306 ms
コンパイル使用メモリ 204,428 KB
実行使用メモリ 6,644 KB
最終ジャッジ日時 2023-10-14 01:28:09
合計ジャッジ時間 6,733 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 4 ms
4,368 KB
testcase_02 AC 4 ms
4,368 KB
testcase_03 AC 7 ms
4,376 KB
testcase_04 AC 582 ms
6,544 KB
testcase_05 AC 832 ms
6,412 KB
testcase_06 AC 834 ms
6,644 KB
testcase_07 AC 829 ms
6,452 KB
testcase_08 AC 369 ms
6,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0