※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 16306번 문제인 Cardboard Container이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/16306
16306번: Cardboard Container
Fidget spinners are so 2017; this years’ rage are fidget cubes. A fidget cube is a cube with unit side lengths, which you hold in your hand and fidget with. Kids these days, right? You work in the planning department for a company that creates and ships
www.acmicpc.net
에라토스테네스의 체를 구하듯이, 중복된 탐색을 줄이기 위해 첫 변의 범위를 세제곱근, 두 번째 변의 길이를 제곱근의 범위로 줄여 탐색하는 것으로 모든 경우의 수를 빠르게 살펴볼 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll ans = 1000000000000000000LL;
ll N; cin >> N;
for (ll i = 1; i * i * i <= N; i++) {
if (N % i) continue;
N /= i;
for (ll j = i; j * j <= N; j++) {
if (N % j) continue;
ll k = N / j;
ans = min(ans, 2 * (i * j + j * k + k * i));
}
N *= i;
}
cout << ans;
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 1743 // C++] 음식물 피하기 (0) | 2021.12.20 |
---|---|
[BOJ 5567 // C++] 결혼식 (0) | 2021.12.19 |
[BOJ 13271 // C++] 스파이 (0) | 2021.12.17 |
[BOJ 6002 // C++] Job Hunt (0) | 2021.12.16 |
[BOJ 13317 // C++] 한 번 남았다 (0) | 2021.12.15 |