結果

問題 No.1022 Power Equation
ユーザー TAISA_TAISA_
提出日時 2020-04-10 22:39:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 2,207 bytes
コンパイル時間 2,274 ms
コンパイル使用メモリ 199,884 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-14 01:34:03
合計ジャッジ時間 2,965 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using V = vector<int>;
using VL = vector<ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void ok() { cerr << "ok" << endl; }
bool so[31][31];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int t;
    cin >> t;
    for (int i = 1; i <= 30; i++) {
        for (int j = 1; j <= 30; j++) {
            if (__gcd(i, j) == 1) {
                so[i][j] = 1;
            }
        }
    }
    while (t--) {
        ll n;
        cin >> n;
        ll res = n * n + n * (n - 1LL);
        for (ll k = 2; k <= 30; k++) {
            ll ok = 0, ng = n + 1;
            auto check = [&](ll x) {
                ll s = 1LL;
                for (int i = 0; i < k; i++) {
                    s *= x;
                    if (s > n) return false;
                }
                return true;
            };
            while (ng - ok > 1LL) {
                ll mid = (ok + ng) / 2LL;
                if (check(mid)) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            ll dc = n / k;
            res += dc * (ok - 1LL) * 2LL;
        }
        for (ll k = 2; k <= 30; k++) {
            for (ll a = 2; a * a <= n; a++) {
                ll s = 1;
                bool f = true;
                if (k >= 3) {
                    for (int i = 0; i < k; i++) {
                        s *= a;
                        if (s > n) f = false;
                    }
                }
                if (!f) break;
                for (ll l = 2; l <= k; l++) {
                    if (so[k][l]) {
                        res += n / max(k, l);
                        if (k > l) {
                            res += n / max(k, l);
                        }
                    }
                }
            }
        }
        cout << res << '\n';
    }
}
0