結果

問題 No.1022 Power Equation
ユーザー Im_GimletIm_Gimlet
提出日時 2020-09-07 02:15:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,601 bytes
コンパイル時間 1,483 ms
コンパイル使用メモリ 166,732 KB
実行使用メモリ 117,572 KB
最終ジャッジ日時 2023-08-19 14:38:27
合計ジャッジ時間 5,185 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int t;

int main() {
    cin >> t;
    while(t--) {
        ll n; cin >> n;
        ll ans = n*n;   // a=c=1のときb,dはどの組み合わせでもよい
        if(n == 1) {
            cout << ans << endl;
            continue;
        }
        ll limit = sqrtl(n);
        vector<bool> num(n+1, true);
        num[0] = false;
        num[1] = false;
        for(ll i = 2; i <= limit; ++i) {
            // a = i
            if(num[i]) {
                ll cnt = 1;
                ll now = i;
                while(1) {
                    if(now*i > n) break;
                    now *= i;
                    cnt++;
                }

                for(ll j = 1; j <= cnt; ++j) {
                    // a = i^j
                    ll a = powl(i, j);
                    num[a] = false;
                    for(ll k = j; k <= cnt; ++k) {
                        // cout << "a=" << a << " c=" << powl(i, k) << endl;
                        if(k == j) ans += n;
                        else ans += ((n/k)*2);
                    }
                }
            }
        }
        for(ll i = limit+1; i <= n; ++i) if(num[i]) ans += n;

        cout << ans << endl;
    }
}
0