https://www.acmicpc.net/problem/3276
3276번: ICONS
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.
www.acmicpc.net
문제
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.
예제 입력 1
2
예제 출력 1
1 2
예제 입력 2
5
예제 출력 2
3 2
예제 입력 3
14
예제 출력 3
4 4
코드
const N = Number(require('fs').readFileSync('/dev/stdin').toString());
let a = 1;
let b = 1;
while(a * b < N){
if(a > b) b++;
else a++;
}
console.log(a + " " + b);
'알고리즘 > 백준' 카테고리의 다른 글
[백준] 3602: iChess / Node.js (JavaScript) (0) | 2023.04.04 |
---|---|
[백준] 3507: Automated Telephone Exchange / Node.js (JavaScript) (0) | 2023.04.03 |
[백준] 2501: 약수 구하기 / Node.js (JavaScript) (0) | 2023.04.01 |
[백준] 15633: Fan Death / Node.js (JavaScript) (0) | 2023.04.01 |
[백준] 18005: Even or Odd? / Node.js (JavaScript) (0) | 2023.03.30 |
댓글