結果

問題 No.1666 累乗数
ユーザー 👑 箱
提出日時 2021-09-03 22:20:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 2,218 bytes
コンパイル時間 1,302 ms
コンパイル使用メモリ 111,056 KB
実行使用メモリ 24,948 KB
最終ジャッジ日時 2023-08-21 22:32:08
合計ジャッジ時間 8,164 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 266 ms
23,904 KB
testcase_01 AC 273 ms
24,592 KB
testcase_02 AC 271 ms
23,984 KB
testcase_03 AC 272 ms
24,404 KB
testcase_04 AC 273 ms
24,800 KB
testcase_05 AC 274 ms
23,648 KB
testcase_06 AC 272 ms
23,608 KB
testcase_07 AC 271 ms
24,308 KB
testcase_08 AC 273 ms
23,668 KB
testcase_09 AC 276 ms
23,680 KB
testcase_10 AC 273 ms
23,480 KB
testcase_11 AC 274 ms
24,108 KB
testcase_12 AC 273 ms
23,956 KB
testcase_13 AC 275 ms
24,284 KB
testcase_14 AC 276 ms
23,276 KB
testcase_15 AC 275 ms
24,068 KB
testcase_16 AC 276 ms
24,432 KB
testcase_17 AC 275 ms
24,008 KB
testcase_18 AC 275 ms
23,632 KB
testcase_19 AC 274 ms
24,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
//#pragma GCC optimize("Ofast, unroll-loops")
#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>
#include <unordered_set>
#include <string>
#include <map>
#include <unordered_map>
#include <random>
#include <set>
#include <cassert>
#include <functional>
#include <queue>
#include <numeric>
#include <bitset>
#include <iterator>

using namespace std;

const int N = 303, M = 18;

mt19937 gen(time(NULL));
#define forn(i, n) for (int i = 0; i < n; i++)
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define mp make_pair
#define endl '\n'

typedef long long ll;

template<typename T = int>
inline T read() {
	T val = 0, sign = 1; char ch;
	for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
		if (ch == '-') sign = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar())
		val = val * 10 + ch - '0';
	return sign * val;
}

vector<ll> cand;

ll root(ll x) {
	ll l = 0, r = 1e9 + 1;
	while (l < r - 1) {
		ll m = (l + r) / 2;
		if (m * m > x)
			r = m;
		else
			l = m;
	}
	return l;
}

void solve() {
    ll k = read<ll>() - 1;
    ll le = 0, ri = 4000000000000000000ll;
    while (ri - le > 1) {
        ll mid = (le + ri) / 2;
    	ll l = 1, r = mid;
	    ll num = upper_bound(all(cand), r) - lower_bound(all(cand), l);
    	num += root(r) - root(l - 1);
	    if (num <= k) {
	        le = mid;
	    } else {
	        ri = mid;
	    }
    }
    printf("%lld\n", ri);
}

void precalc() {
	ll U = 1e18;
	vector<ll> _cand = { 1 };
	for (ll i = 2; i <= 1e6; i++)
		for (ll curr = i * i * i; curr <= U; curr *= i) {
			_cand.push_back(curr);
			if (curr > U / i) break;
		}

	sort(all(_cand));
	_cand.erase(unique(all(_cand)), _cand.end());

	for (const ll &u : _cand) {
		ll x = root(u);
		if (x * x == u) continue;
		cand.push_back(u);
	}

    debug("Precalc: %.3f\n", (double)(clock()) / CLOCKS_PER_SEC);
}

signed main() {
    precalc();
	int t = read();
    clock_t tot = clock();
	while (t--) {
		clock_t z = clock();
		solve();
		//debug("Test: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
	}
    debug("Total Time: %.3f\n", (double)(clock() - tot) / CLOCKS_PER_SEC);
}
0