Submission #20943325


Source Code Expand

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 };
    HashSet<Long> set = new HashSet<Long>();

    long[] a = new long[n];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }

    Arrays.sort(a);

    for (int j = 0; j < primes.length; j++) {
      if ((a[0] % primes[j]) == 0) {
        set.add(primes[j]);
        break;
      }
    }

    for (int i = 1; i < n; i++) {
      boolean add = false;
      for (long tmp : set) {
        if ((a[i] % tmp) == 0) {
          add = true;
          break;
        }
      }

      if (!add) {
        for (int j = 0; j < primes.length; j++) {
          if (((a[i] % primes[j]) == 0) && !set.contains(primes[j])) {
            set.add(primes[j]);
            break;
          }
        }
      }
    }

    long ans = 1;
    for (long t : set) {
      ans *= t;
    }

    System.out.println(ans);
  }
}

Submission Info

Submission Time
Task A - Not coprime
User taichey1207
Language Java (OpenJDK 11.0.6)
Score 0
Code Size 1189 Byte
Status WA
Exec Time 186 ms
Memory 35732 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 3
AC × 11
WA × 5
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 186 ms 35608 KiB
02.txt AC 109 ms 35684 KiB
03.txt WA 106 ms 35616 KiB
04.txt WA 101 ms 35612 KiB
05.txt AC 108 ms 35652 KiB
06.txt AC 105 ms 35544 KiB
07.txt AC 115 ms 35580 KiB
08.txt AC 117 ms 35632 KiB
09.txt AC 105 ms 35652 KiB
10.txt AC 116 ms 35620 KiB
11.txt WA 111 ms 35732 KiB
12.txt WA 115 ms 35540 KiB
13.txt WA 115 ms 35596 KiB
s1.txt AC 109 ms 35704 KiB
s2.txt AC 105 ms 35536 KiB
s3.txt AC 111 ms 35580 KiB