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.
https://www.acmicpc.net/problem/3276
입력
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.
예제
# input
2
# output
1 2
# input
5
# output
3 2
# input
14
# output
4 4
문제 풀이
# 1
N = int(input())
row = 1
col = 1
while True:
if row * col < N:
row += 1
else:
break
if row * col < N:
col += 1
else:
break
print(row, col)
# 2
N = int(input())
ans = int(N**0.5)
if N <= ans**2:
print(ans, ans)
elif N <= (ans+1) * ans:
print(ans+1, ans)
else:
print(ans+1, ans+1)
파이썬을 독학하시는 분들에게 도움이 되길 바라며,
혹 더 좋은 방법이 있거나 오류가 있다면 편하게 말씀 부탁드립니다.
728x90