結果

問題 No.1022 Power Equation
ユーザー ngtkanangtkana
提出日時 2020-04-10 22:04:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 882 bytes
コンパイル時間 2,188 ms
コンパイル使用メモリ 198,744 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 00:36:12
合計ジャッジ時間 2,609 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
lint port(lint x,lint y){
    if(y==1)return x;
    if(y==2)return std::sqrt(x);
    if(y==3)return std::cbrt(x);
    if(35<y)return 1;
    lint i=1;
    for(;;i++){
        lint p=1;
        for(lint j=0;j<y;j++)p*=i;
        if(x<p)break;
    }
    return i-1;
}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint t;std::cin>>t;
    while(t--){
        lint n;std::cin>>n;
        lint ans=0;
        lint lg=std::log2(n);
        for(lint p=1;p<=lg;p++){
        for(lint q=1;q<=lg;q++){
            if(std::gcd(p,q)!=1)continue;
            lint r=std::max(p,q);
            ans+=(port(n,r)-1)*(n/r);
        }}
        ans+=n*n;
        std::cout<<ans<<'\n';
    }
}
0