結果

問題 No.376 立方体のN等分 (2)
ユーザー bal4ubal4u
提出日時 2019-05-11 06:04:09
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 709 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 31,232 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-02 01:08:20
合計ジャッジ時間 3,318 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 35 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.375 立方体のN等分 (1)
//               376 立方体のN等分 (2)
// 2019.5.11 bal4u

#include <stdio.h>
#include <math.h>

long long comb(int x, long long n) {
	long long min, s;
	int b, y;
	min = n-1, b = (int)sqrt((double)n);
	for (y = b; y >= x; y--) {
		if (n%y == 0) return y + n/y - 2;
	}
	return min;
}

int main()
{
	long long N, min, s;
	int b, x;
	
	scanf("%lld", &N);
	b = 1+(int)pow((double)N, 1.0/3);
	min = N-1;for (x = 2; x <= b; x++) if (N%x == 0) {
		s = x-1 + comb(x, N/x); if (s < min) min = s;
	}
	if (min == N-1) {
		b = (int)sqrt((double)N);
		for ( ; x <= b; x++) if (N%x == 0) {
			min = x+N/x+2;
			break;
		}
	}
	printf("%lld %lld\n", min, N-1);
	return 0;
}
0