結果

問題 No.1666 累乗数
ユーザー CleyLCleyL
提出日時 2022-08-28 11:41:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,364 bytes
コンパイル時間 1,024 ms
コンパイル使用メモリ 100,500 KB
実行使用メモリ 11,596 KB
最終ジャッジ日時 2024-04-23 10:33:40
合計ジャッジ時間 3,800 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
11,336 KB
testcase_01 AC 95 ms
11,336 KB
testcase_02 AC 100 ms
11,464 KB
testcase_03 AC 100 ms
11,464 KB
testcase_04 AC 97 ms
11,596 KB
testcase_05 AC 98 ms
11,336 KB
testcase_06 AC 100 ms
11,336 KB
testcase_07 AC 101 ms
11,336 KB
testcase_08 AC 102 ms
11,332 KB
testcase_09 AC 99 ms
11,492 KB
testcase_10 AC 98 ms
11,596 KB
testcase_11 AC 99 ms
11,468 KB
testcase_12 AC 100 ms
11,592 KB
testcase_13 AC 100 ms
11,332 KB
testcase_14 AC 99 ms
11,336 KB
testcase_15 AC 99 ms
11,464 KB
testcase_16 AC 99 ms
11,468 KB
testcase_17 AC 98 ms
11,336 KB
testcase_18 AC 97 ms
11,356 KB
testcase_19 AC 98 ms
11,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    vector<long long> A;
    for(long long i = 2; 1000000 > i; i++){
        long long nw = i*i;
        while(1000000000000000000/i >= nw){
            nw *= i;
            if((long long)sqrt(nw) * (long long)sqrt(nw) == nw)continue;
            A.push_back(nw);
        }

    }
    sort(A.begin(),A.end());
    A.erase(unique(A.begin(),A.end()),A.end());
    
    int t;cin>>t;
    for(int i = 0; t > i; i++){
        long long x;cin>>x;
        long long mn = 0;
        long long mx = A.size()+1;
        while(mx-mn > 1){
            long long ce = (mx+mn)/2;
            long long ele;
            if(ce == 0){
                ele = 0;
            }else if(ce == A.size()){
                ele = 1000000000+ce-1;
            }else{
                ele = ce+(long long)sqrt(A[ce-1]);
            }
            if(ele <= x){
                mn = ce;
            }else{
                mx = ce;
            }
        }
        //cout << mn << endl;
        if(mn && mn+(long long)sqrt(A[mn-1]) == x){
            //cout << "!!" << endl;
            cout << A[mn-1] << endl;
        }else{
            long long diff = x-(mn+(long long)sqrt(A[mn-1]));
            long long re = sqrt(A[mn-1])+diff;
            cout << re*re << endl;
        }
    }
}
0