結果

問題 No.1022 Power Equation
ユーザー NewGardenNewGarden
提出日時 2020-04-11 13:12:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,200 bytes
コンパイル時間 1,897 ms
コンパイル使用メモリ 168,904 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 02:37:41
合計ジャッジ時間 2,608 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;


ll powll(ll n,ll k){ ll ret=1; while(k){ if(k&1)ret=ret*n; n=n*n; k>>=1; } return ret; }

uint64_t kth_root(uint64_t a, int k) {
  if(k == 1) return a;
  auto check = [&](uint32_t x) {
    uint64_t mul = 1;
    for(int j = 0; j < k; j++) {
      if(__builtin_mul_overflow(mul, x, &mul)) return false;
    }
    return mul <= a;
  };
  uint64_t ret = 0;
  for(int i = 31; i >= 0; i--) {
    if(check(ret | (1u << i))) ret |= 1u << i;
  }
  return ret;
}

vector<int> cnt(30,0);

void ch(ll n){
  rep(i,30) cnt[i]=0;
  cnt[1] = n;
  REP(i,2,30){
    cnt[i] = kth_root(n,i);
  }
}

ll gcd(ll a, ll b){ return b ? gcd(b,a%b):a; }

int main(){
  int t;
  cin >> t;
while(t--){
  ll n;
  cin >> n;
  ch(n);
  ll ans = n*(2*n-1);
  for(int i=2; i<=n && i<30; i++)for(int j=1; j<i; j++)if(gcd(i,j)==1){
    ans += (cnt[i]-1)*(n/i)*2;
  }
  cout << ans << endl;
}
  return 0;
}
0