結果

問題 No.1176 少ない質問
コンテスト
ユーザー pengin_2000
提出日時 2021-08-29 19:49:55
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 747 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 281 ms
コンパイル使用メモリ 38,848 KB
最終ジャッジ日時 2026-02-22 07:55:40
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #
raw source code

#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