結果

問題 No.1022 Power Equation
ユーザー merom686merom686
提出日時 2020-04-10 22:32:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,075 bytes
コンパイル時間 776 ms
コンパイル使用メモリ 75,116 KB
実行使用メモリ 4,484 KB
最終ジャッジ日時 2023-10-14 01:17:27
合計ジャッジ時間 2,193 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int gcd(int n, int m) {
    if (n < m) swap(n, m);
    while (m != 0) {
        int r = n % m;
        n = m;
        m = r;
    }
    return n;
}

int main() {
    int t;
    cin >> t;

    for (int _ = 0; _ < t; _++) {
        ll n;
        cin >> n;

        ll r = 0;

        int m = (int)sqrt(n);
        vector<int> a(m + 1, 0);
        for (int k = 2; k <= m; k++) {
            if (a[k]) continue;

            int c = 0;
            for (int l = k; l <= n; l *= k) {
                if (l <= m) a[l] = 1;
                c++;
            }
            for (int i = 1; i <= c; i++) {
                for (int j = 1; j < i; j++) {
                    int g = gcd(i, j);
                    int i1 = i / g, j1 = j / g;
                    r += n / i1;
                }
            }
        }

        r *= 2;
        r += n * n - n + n * n;

        cout << r << '\n';
    }

    return 0;
}
0