結果

問題 No.1022 Power Equation
ユーザー kappybarkappybar
提出日時 2020-04-11 16:29:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 1,108 bytes
コンパイル時間 1,725 ms
コンパイル使用メモリ 169,320 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 08:09:18
合計ジャッジ時間 2,804 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const int INF = 1e9;
const int MOD = 1000000007;

ll gcd(ll i,ll j){
        if(j == 0) return i;
        return gcd(j,i%j);
}

long long int_pow(long long a, long long b){
        bitset<30> bit(b);
        string s = bit.to_string();
        long long ret = 1;
        for (int i = 0;i< s.length(); ++i){
                ret = (ret * ret);
                if(s[i]-'0') ret = (ret * a) ;
        }
        return ret;
}


void solve(){
    ll n;
    cin >> n;
    vector<int> POW_ok(36,1);
    ll ans = n*n;
    POW_ok[1] = n;
    for(int i=2;i<36;i++){
        while(int_pow(POW_ok[i],i) <= n) POW_ok[i] ++;
        POW_ok[i]--;
    }
    for(int i=1;i<=35;i++){
        for(int j=1;j<=35;j++){
            if(gcd(i,j) > 1) continue;
            ll res = min(POW_ok[i]-1,POW_ok[j]-1);
            res *= n/max(i,j);
            ans += res;
        }
    }
    cout << ans << endl;
    return;
}

int main(){
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}
0