Common Divisors

Interview

Time limit1sMemory limit256 MB

Summary
Given 2 or 3 numbers up to 1e8, print every positive integer that divides all of them, in increasing order.
Level

Easy3 of 10

Topics
Math, Number theory, Sorting, Brute force
Solved
No attempts yet

Problem

You are given nn natural numbers. Write a program that finds all of their common divisors.

Input

The first line contains nn, which is either 2 or 3. The second line contains the nn natural numbers whose common divisors you must find. Every number is at most 10810^8.

Output

Print the common divisors of the given nn numbers, one per line, in increasing order.

Examples3

  1. Example 1

    Input
    2
    75 125
    
    Expected output
    1
    5
    25
    
  2. Example 2

    Input
    3
    110 22 88
    
    Expected output
    1
    2
    11
    22
    
  3. Example 3

    Input
    3
    66 11 3
    
    Expected output
    1