結果

問題 No.1022 Power Equation
ユーザー merom686merom686
提出日時 2020-04-10 22:33:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,074 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 76,204 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 01:19:40
合計ジャッジ時間 1,375 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 (ll 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