Home [BOJ 1037] 약수
Post
Cancel

[BOJ 1037] 약수

약수 (1037번)

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

풀이방법

  • 문제 내용에서 어떤 수 N의 진짜 약수가 모두 주어진다 하였으므로 정렬 후 맨 처음과 마지막을 곱하면 N을 구할 수 있다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        
        int[] arr = new int[N];
        for(int i=0; i<N; i++) {
            arr[i] = Integer.parseInt(st.nextToken());
        }
        
        Arrays.sort(arr);
        System.out.println(arr[0] * arr[N-1]);
    }
}

This post is licensed under CC BY 4.0 by the author.

[BOJ 6603] 로또

[BOJ 5565] 영수증

Comments powered by Disqus.