結果

問題 No.1664 Unstable f(n)
ユーザー ohreitetsuohreitetsu
提出日時 2021-09-04 17:11:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,039 bytes
コンパイル時間 551 ms
コンパイル使用メモリ 68,216 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-23 06:07:20
合計ジャッジ時間 7,586 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 18 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 387 ms
4,380 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <math.h>
using namespace std;
typedef long long LL;
int main()
{
	LL N,n;
	cin >> N;
	if (N == 1) {
		cout << 1 << endl;
		return 0;
	}
	int i = 1;
	int j = 0;
	LL Min1=0, Min2=0;
	LL Ni = 0, Nj = 0;
	int I1=0, J1=0, I2=0, J2=0;
	bool bLoop = true;
	for (i = 2; i > 0; i++) {
		for (j = 2; j >= 0; j++) {
			n = (LL)pow(i, j);
			if (n == N) {
				Min1 = i + j;
				bLoop = false;
				break;
			}else if (n>N){
				I1 = i;
				J1 = j-1;
				Nj = (LL)pow(I1, J1);
				Min1 = (int)(I1 + J1 + (N - Nj));
				bLoop = false;
				break; 
			}
		}
		if (!bLoop) {
			break;
		}
	}
	bLoop = true;
	for (j = 2; j > 0; j++) {
		for (i = I1+1; i >= 0; i++) {
			n = (LL)pow(i, j);
			if (n == N) {
				Min2 = i + j;
				bLoop = false;
				break;
			}else if (n>N){
				I2 = i-1;
				J2 = j;
				Ni = (LL)pow(I2, J2);
				Min2 = (int)(I2 + J2 + (N - Ni));
				bLoop = false;
				break;
			}
		}
		if (!bLoop) {
			break;
		}
	}
	if (Min1 < Min2) {
		cout << Min1 << endl;
	}
	else {
		cout << Min2 << endl;
	}
	return 0;
}
0