結果

問題 No.1666 累乗数
ユーザー publflpublfl
提出日時 2021-09-03 21:57:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,960 ms / 2,000 ms
コード長 1,261 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 56,152 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 21:37:49
合計ジャッジ時間 37,539 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
4,380 KB
testcase_01 AC 1,836 ms
4,384 KB
testcase_02 AC 1,834 ms
4,380 KB
testcase_03 AC 1,843 ms
4,380 KB
testcase_04 AC 1,834 ms
4,380 KB
testcase_05 AC 1,952 ms
4,380 KB
testcase_06 AC 1,960 ms
4,376 KB
testcase_07 AC 1,954 ms
4,380 KB
testcase_08 AC 1,956 ms
4,384 KB
testcase_09 AC 1,859 ms
4,376 KB
testcase_10 AC 1,846 ms
4,380 KB
testcase_11 AC 1,865 ms
4,380 KB
testcase_12 AC 1,857 ms
4,380 KB
testcase_13 AC 1,929 ms
4,376 KB
testcase_14 AC 1,925 ms
4,380 KB
testcase_15 AC 1,925 ms
4,376 KB
testcase_16 AC 1,932 ms
4,380 KB
testcase_17 AC 1,880 ms
4,380 KB
testcase_18 AC 1,896 ms
4,380 KB
testcase_19 AC 1,874 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <map>
#define MAX (long long int)1e18

int check[110];
std::vector<int> prime;
std::map<long long int, long long int> M;
long long int func(int k, int mul,long long int val)
{
	if(mul>60) return 0;
	if(k==prime.size())
	{
		if(mul==1) return 0;
		long long int min = 1, max = val;
		long long int p = 1;
		if(mul>=20) max = 10;
		else if(mul>=10) max = 100;
		else if(mul>=6) max = 1000;
		else if(mul>=3) max = 1000000;
		else max = 1000000000;
		while(min<=max)
		{
			long long int h = (min+max)/2;
			long long int t = val;
			for(int i=1;i<=mul;i++) t/=h;
			if(t==0) max = h-1;
			else
			{
				p = h;
				min = h+1;
			}
		}
		return p-1;
	}
	
	long long int s1 = func(k+1,mul,val);
	long long int s2 = func(k+1,mul*prime[k],val);
	return s1-s2;
}

int main()
{
	for(int i=2;i<=60;i++)
	{
		if(check[i]==0)
		{
			prime.push_back(i);
			for(int j=i;j<=60;j+=i) check[j] = 1;
		}
	}
	
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int a;
		scanf("%d",&a);
		long long int min = 1, max = MAX;
		long long int ans = MAX;
		while(min<=max)
		{
			long long int h = (min+max)/2;
			long long int s = -func(0,1,h)+1;
			if(s>=a)
			{
				ans = h;
				max = h-1;
			}
			else min = h+1;
		}
		printf("%lld\n",ans);
	}
}
0