문제 링크입니다: https://www.acmicpc.net/problem/4619
4619번: 루트
입력은 여러 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있고, B와 N이 주어진다. (1 ≤ B ≤ 1,000,000, 1 ≤ N ≤ 9) 입력의 마지막 줄에는 0이 2개 주어진다.
www.acmicpc.net
간단한 구현 문제였습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
while (1) | |
{ | |
int B, N; | |
cin >> B >> N; | |
if (B == 0 && N == 0) | |
{ | |
break; | |
} | |
int A = 1; | |
int A_N = 1; | |
for (int num = 1; ; num++) | |
{ | |
int temp = 1; | |
for (int i = 0; i < N; i++) | |
{ | |
temp *= num; | |
} | |
if (abs(temp - B) < abs(B - A_N)) | |
{ | |
A = num; | |
A_N = temp; | |
} | |
if (temp > B) | |
{ | |
break; | |
} | |
} | |
cout << A << "\n"; | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 4635번 Speed Limit (0) | 2021.05.16 |
---|---|
백준 4623번 Copier Reduction (0) | 2021.05.16 |
백준 4504번 배수 찾기 (0) | 2021.05.15 |
백준 4493번 가위 바위 보? (0) | 2021.05.15 |
백준 4388번 받아올림 (0) | 2021.05.15 |