結果

問題 No.1666 累乗数
ユーザー kotatsugamekotatsugame
提出日時 2021-09-03 22:04:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 933 ms / 2,000 ms
コード長 1,005 bytes
コンパイル時間 864 ms
コンパイル使用メモリ 78,084 KB
実行使用メモリ 25,020 KB
最終ジャッジ日時 2023-08-21 21:58:06
合計ジャッジ時間 21,365 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 906 ms
24,488 KB
testcase_01 AC 917 ms
23,960 KB
testcase_02 AC 915 ms
24,608 KB
testcase_03 AC 921 ms
24,764 KB
testcase_04 AC 921 ms
23,480 KB
testcase_05 AC 929 ms
25,020 KB
testcase_06 AC 928 ms
23,368 KB
testcase_07 AC 931 ms
23,748 KB
testcase_08 AC 930 ms
23,424 KB
testcase_09 AC 923 ms
24,076 KB
testcase_10 AC 926 ms
24,736 KB
testcase_11 AC 924 ms
24,828 KB
testcase_12 AC 925 ms
24,100 KB
testcase_13 AC 931 ms
24,108 KB
testcase_14 AC 929 ms
23,608 KB
testcase_15 AC 930 ms
23,500 KB
testcase_16 AC 933 ms
23,660 KB
testcase_17 AC 927 ms
23,464 KB
testcase_18 AC 925 ms
24,856 KB
testcase_19 AC 926 ms
23,972 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:37:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   37 | 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,Sq;
long cnt(long N)
{
	long ans=0;
	ans+=upper_bound(Sq.begin(),Sq.end(),N)-Sq.begin();
	long now=sq(N,2);
	ans+=now;
	return ans;
}
main()
{
	const long LIM=1e18;
	for(long a=2;;a++)
	{
		bool ch=false;
		long t=a*a;
		if(t>LIM/a)break;
		while(t<=LIM/a)
		{
			t*=a;
			S.push_back(t);
		}
	}
	sort(S.begin(),S.end());
	S.erase(unique(S.begin(),S.end()),S.end());
	for(long t:S)
	{
		long now=sq(t,2);
		if(now*now!=t)Sq.push_back(t);
	}
	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