結果

問題 No.1666 累乗数
ユーザー kotatsugamekotatsugame
提出日時 2021-09-03 22:00:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,078 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 77,808 KB
実行使用メモリ 13,164 KB
最終ジャッジ日時 2023-08-21 21:46:47
合計ジャッジ時間 4,164 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
11,880 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:38:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   38 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long sq(long N,long k)
{
	if(k>=30)return 1;
	long L=0,R=N+1;
	while(R-L>1)
	{
		long mid=(L+R)/2;
		long t=1;
		bool ok=true;
		for(int i=0;i<k;i++)
		{
			if(t>N/mid)
			{
				ok=false;
				break;
			}
			t*=mid;
		}
		if(ok)L=mid;
		else R=mid;
	}
	return L;
}
vector<long>S;
long cnt(long N)
{
	long ans=0;
	ans+=upper_bound(S.begin(),S.end(),N)-S.begin();
	long now=sq(N,2);
	ans+=now;
	ans-=sq(now,2)-1;
	return ans;
}
main()
{
	const long LIM=1e18;
	for(long k=3;;k++)
	{
		bool ch=false;
		for(long a=2;;a++)
		{
			long b=1;
			bool ok=true;
			for(int i=0;i<k;i++)
			{
				if(b>LIM/a)
				{
					ok=false;
					break;
				}
				b*=a;
			}
			if(!ok)break;
			S.push_back(b);
			ch=true;
		}
		if(!ch)break;
	}
	sort(S.begin(),S.end());
	S.erase(unique(S.begin(),S.end()),S.end());
	int T;
	//cout<<cnt(4)<<endl;
	//return 0;
	cin>>T;
	for(;T--;)
	{
		long K;cin>>K;
		long L=0,R=1e18;
		while(R-L>1)
		{
			long mid=(L+R)/2;
			if(cnt(mid)<K)L=mid;
			else R=mid;
		}
		cout<<R<<endl;
	}
}
0