Baekjoon Algorithm | Problem 1037: Divisors

Source

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

Problem

Solve Baekjoon Online Judge problem 1037, Divisors.

Input

Follow the input format and constraints given in the original problem statement.

Output

Print the answer required by the problem.

Sample Input 1

2 4 2

Sample Output 1

8

Sample Input 2

1 2

Sample Output 2

4

Sample Input 3

6 3 4 2 12 6 8

Sample Output 3

24

Sample Input 4

14 14 26456 2 28 13228 3307 7 23149 8 6614 46298 56 4 92596

Sample Output 4

185192

Algorithm Classification

  • Math
  • Brute Force
  • Number Theory

Solution

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            int n = Integer.parseInt(br.readLine());
            StringTokenizer nums = new StringTokenizer(br.readLine(), " ");

            int max = Integer.MIN_VALUE;
            int min = Integer.MAX_VALUE;
            for(int i = 0; i < n; i++) {
                int num  = Integer.parseInt(nums.nextToken());
                if(num > max) max = num;
                if(num < min) min = num;
            }
            System.out.println(max * min);

        }
    }
}