PS/Baekjoon Online Judge

[백준 03276] ICONS [Java]

kimyoungrok 2023. 11. 24. 17:11
728x90

문제

Dave has a collection of N interesting pebbles. He wishes to arrange them in rows and columns in such a way that the sum of number of rows and number of columns needed is minimal possible. Write a program that will help Dave to find such numbers. 

입력

The first and only line of input file contains a natural number N (1 ≤ N ≤ 100), the number of pebbles to be arranged. Arrangement needs not to be regular in any sense – some places in a row may be empty.

출력

The first and only line of output file must contain number of rows and number of columns separated by one space.

Note: A solution needs not to be unique.

 

풀이

행( row )과 열( col )의 곱이 주어진 수 N이상이 되는 최솟값을 찾으면 된다.

두 수의 곱이 최대가 되도록 분배할 때는 두 수가 비슷할수록 최대가 된다. 따라서 1씩 번갈아 증가하며 최솟값을 찾자.


소스코드

보기


 

출처

https://www.acmicpc.net/problem/3276

728x90