Playing with Factors


Submit solution

Points: 10 (partial)
Time limit: 8.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Python

Problem Definition

Given a collection of N unique numbers, do the following tasks as a menu-driven Program. Please note that the menu runs only once.

  1. Print the numbers in the collection, which are factors of at least one other number in the same collection. If no such number exists in the collection, print the message "Null". For example, if the collection contains 10, 5, 33, and 11, the expected output is 5 (as it is a factor of 10) and 11 (as it is a factor of 33).

  2. Generate the factors of each number in the collection and create a combined collection of factors of all N numbers. Print the factor that is the most common, excluding 1. Note that any factor that is occurring once is not considered as a common factor.

Input Format

The first input is the number of elements, N.

The next N inputs are the numbers.

The next input is the choice of operation - 1 or 2.

Output Format

For option 1, print the numbers in the collection, which are factors of at least one other number in the same collection. If there are multiple numbers, they are printed on the same line, separated by a single space. If no such number is not present in the collection, it will print the message "Null".

Option 2, prints the number, other than 1, which is a factor for most of the N numbers. If multiple such numbers are there, the numbers are printed in the same line separated by a single space. If no such number exists, print "Null"

If the option is neither 1 nor 2, a message "Error" is printed as output.

Sample Input1

3

49

15

7

1

Sample Output1

7

Explanation

7 is a factor for 49.

Sample Input2

3

49

15

7

2

Sample Output1

7

Explanation

The total list of factors are 1,7,49 for 49, 1,3,5,15 for 15, and 1,7 for 7. Excluding 1, 7 occurs twice and no other factors occur more than once.


Comments

There are no comments at the moment.