結果

問題 No.375 立方体のN等分 (1)
ユーザー bal4ubal4u
提出日時 2019-05-10 22:24:24
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 106 ms / 5,000 ms
コード長 673 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 31,744 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-02 01:03:22
合計ジャッジ時間 1,512 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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

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