알고리즘 및 자료구조/문제

백준알고리즘 15667번 2018 연세대학교 프로그램

ktko 2018. 5. 1. 23:31

백준알고리즘


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


문제에 따라 하나하나씩 계산을 해 보면..


3 : 1 + 3 + 9 13

4 : 1 + 4 + 16 21

5 : 1 + 5 + 25 31

6 : 1 + 6 + 36 43

7 : 1 + 7 + 49 57

8 : 1 + 8 + 64 73

9 : 1 + 9 + 81 91

10 : 1 + 10 + 100 111

과 같다는 것을 알 수 있다. 결국 루트로 입력받은 값을 계산해서 int로 형변환을 하면 정답.

import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int input = Integer.parseInt(scan.nextLine().trim());
        
        System.out.println((int)Math.sqrt(input));
        scan.close();
    } 
}