Programming contests

50 Programming Exercise for Beginners

January 2, 2019, 12:00 AM – December 31, 2019, 12:00 AM

Prime or Not?

Write a program that helps you determine whether the elements of a sequence of numbers are all prime numbers.

The input consists of several lines. Each line contains integers; if there are more numbers, they will be separated from each other by exactly one space character within the line. The first number of each line (n) specifies the number of numbers to be examined in that line. For each line, your program must determine whether the additional n numbers are all prime numbers. The end of the input is indicated by a line where n = 0. As a hint, we mention that the smallest prime number is 2.

For each line, your program should write „YES” to the standard output if all numbers in the line are prime numbers, or „NO” if there is at least one number among the numbers that is not prime.

Sample Input

  1. 1 1
  2. 1 2
  3. 5 2 3 5 7 11
  4. 5 2 3 4 5 7
  5. 5 3 11 5 7 2
  6. 5 11 7 3 9 5
  7. 0
download as text file

Output for Sample Input

  1. NO
  2. YES
  3. YES
  4. NO
  5. YES
  6. NO
download as text file
Acknowledgement This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.
University of Debrecen; Faculty of Informatics; v. 09/30/2024