結果

問題 No.1022 Power Equation
ユーザー betrue12betrue12
提出日時 2020-04-10 21:37:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 680 bytes
コンパイル時間 2,004 ms
コンパイル使用メモリ 199,452 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 23:39:37
合計ジャッジ時間 2,447 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int64_t powint(int64_t N, int K){
    int64_t res = 1;
    while(K--) res *= N;
    return res;
}

int main(){
    int T;
    cin >> T;
    while(T--){
        int64_t N;
        cin >> N;
        vector<int64_t> pwmax(31, 1);
        pwmax[1] = N;
        for(int i=2; i<=30; i++) while(powint(pwmax[i]+1, i) <= N) pwmax[i]++;

        int64_t ans = N*N;
        for(int i=1; i<=30; i++) for(int j=1; j<=30; j++){
            if(gcd(i, j) > 1) continue;
            int m = max(i, j);
            int64_t res = pwmax[m]-1;
            res *= N/m;
            ans += res;
        }
        cout << ans << endl;
    }
    return 0;
}
0