結果

問題 No.1664 Unstable f(n)
ユーザー pengin_2000pengin_2000
提出日時 2021-09-03 22:00:08
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,101 bytes
コンパイル時間 906 ms
コンパイル使用メモリ 29,276 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 21:44:51
合計ジャッジ時間 2,325 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 0 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 0 ms
4,380 KB
testcase_22 AC 0 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 0 ms
4,380 KB
testcase_27 AC 0 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 0 ms
4,380 KB
testcase_30 AC 0 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 0 ms
4,380 KB
testcase_33 AC 0 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,384 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,384 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 0 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:2:15: 警告: 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: 備考: ‘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;
}
int f(long long int a, long long int b, long long int c)
{
	if (a == 0)
		return 1;
	long long int res = 1;
	while (b > 0)
	{
		if (b % 2 > 0)
		{
			if (res > c / a)
				return 0;
			res = res * a;
		}
		if (a > c / a && b != 1)
			return 0;
		a = a * a;
		b /= 2;
	}
	return 1;
}
long long int root(long long int n, long long int r)
{
	if (r > 3)
	{
		long long int i;
		for (i = 0;; i++)
		{
			if (f(i, r, n) == 0)
				return i - 1;
		}
	}
	long long int min, mid, max;
	min = -1;
	max = 1000000009;
	if (r == 3)
		max = 1000006;
	while (max - min > 1)
	{
		mid = (max + min) / 2;
		if (pow(mid, r) > n)
			max = mid;
		else
			min = mid;
	}
	return min;
}
int main()
{
	long long int n;
	scanf("%lld", &n);
	long long int i, j, k;
	long long int ans = n;
	for (j = 2; j < 100; j++)
	{
		i = root(n, j);
		k = n - pow(i, j);
		if (ans > i + j + k)
			ans = i + j + k;
	}
	printf("%lld\n", ans);
	return 0;
}
0