結果

問題 No.1176 少ない質問
ユーザー pengin_2000pengin_2000
提出日時 2021-08-29 19:49:55
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 747 bytes
コンパイル時間 757 ms
コンパイル使用メモリ 29,184 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-01 23:38:32
合計ジャッジ時間 1,471 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:2:15: warning: conflicting types for built-in function 'pow'; expected 'double(double,  double)' [-Wbuiltin-declaration-mismatch]
    2 | long long int pow(long long int a, long long int n)
      |               ^~~
main.c:2:1: note: 'pow' is declared in header '<math.h>'
    1 | #include<stdio.h>
  +++ |+#include <math.h>
    2 | long long int pow(long long int a, long long int n)

ソースコード

diff #

#include<stdio.h>
long long int pow(long long int a, long long int n)
{
	long long int res = 1;
	while (n > 0)
	{
		if (n % 2 > 0)
			res = res * a;
		a = a * a;
		n /= 2;
	}
	return res;
}
long long int root(long long int a, long long int n)
{
	long long int min, mid, max;
	min = 0;
	max = 1;
	if (n == 2)
	{
		while (pow(max, n) < a)
			max *= 2;
	}
	else
	{
		while (pow(max, n) < a)
			max++;
	}
	while (max - min > 1)
	{
		mid = (max + min) / 2;
		if (pow(mid, n) < a)
			min = mid;
		else
			max = mid;
	}
	return max;
}
int main()
{
	long long int a;
	scanf("%lld", &a);
	long long int i, ans = a, r;
	for (i = 2;; i++)
	{
		r = root(a, i);
		if (ans > r * i)
			ans = r * i;
		if (r == 2)
			break;
	}
	printf("%lld\n", ans);
	return 0;
}
0