結果

問題 No.1022 Power Equation
ユーザー kyort0nkyort0n
提出日時 2020-04-10 21:52:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,143 ms / 2,000 ms
コード長 1,823 bytes
コンパイル時間 2,237 ms
コンパイル使用メモリ 167,272 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 00:23:39
合計ジャッジ時間 7,327 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;

bool ok(ll x) {
    vector<ll> v;
    for(ll i = 2; i * i <= x; i++) {
        if(x % i == 0) {
            v.push_back(0);
            while(x % i == 0) {
                v.back()++;
                x /= i;
            }
        }
    }
    //if(x != 1) v.push_back(1);
    if(x != 1) return true;
    ll g = 0;
    for(auto val : v) {
        g = __gcd(val, g);
    }
    return g == 1;
}

ll N;

ll g(ll x) {
    ll ret = 0;
    for(ll i = 1; i <= x; i++) {
        for(ll j = 1; j <= x; j++) {
            ll g = __gcd(i, j);
            ll M = max(i, j);
            ll m = min(i, j);
            M /= g;
            m /= g;
            ret += N / M;
        }
    }
    return ret;
}

void solve() {
    cin >> N;
    ll ans = N * N;
    ll Total = N - 1;
    for(ll i = 2; i * i <= N; i++) {
        if(ok(i)) {
            //cerr << i << endl;
            ll num = 0;
            for(ll j = i; j <= N; j *= i) {
                num++;
            }
            Total -= num;
            //cerr << i << " " << num << " " << g(num) << endl;
            ans += g(num);
        }
    }
    //cerr << Total << endl;
    ans += Total * N;
    cout << ans << endl;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll T;
    cin >> T;
    while(T--) solve();
    return 0;
}
0