In math class, Mimi learned about primes! To test her knowledge, her teacher assigned her the following problem for homework:
Given an array of elements, determine the largest prime number which divides every element of the array, or
DNE
if no such prime exists.
Mimi was sleeping in class, so she has no idea how to approach this problem! Can you write a program to help her finish her homework?
Python users are recommended to use PyPy over CPython. There is a significant performance increase.
Constraints
Subtask 1 [10%]
Subtask 2 [90%]
Input Specification
The first line of input will contain a single integer, .
The next line of input will contain space separated integers, .
Output Specification
The output should consist of a single line, either the largest prime which divides all elements in the array, or DNE
if no such prime exists.
Sample Input
5
6 12 18 24 30
Sample Output
3
Comments
so sad ;( tle'd case 27. Is there any way to make my code any faster? Or is it wrong?
Consider the case where
res
is the square of a prime.I'm getting a
TLE
on Case #7 with C although I think I am using the optimal algorithm. Does anyone know certain points I might be missing?This comment is hidden due to too much negative feedback. Show it anyway.
Thanks. It was the integer overflow error.
It would print squared numbers until the squared number is >= 3_000_000_000. Would it just take too long? Is the int too small?
I don't know why my code is producing a input mismatch exception....
Each can be up to , which does not fit in an int. You'll need long to pass.
This comment is hidden due to too much negative feedback. Show it anyway.
1 is not a prime number