We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Mathematics
  3. Number Theory
  4. Easy GCD

Easy GCD

Problem
Submissions
Leaderboard
Discussions
Editorial

We call a sequence of non-negative integers, , awesome if there exists some positive integer such that each element in (where ) is evenly divisible by . Recall that evenly divides if there exists some integer such that .

Given an awesome sequence, , and a positive integer, , find and print the maximum integer, , satisfying the following conditions:

  1. is also awesome.

Input Format

The first line contains two space-separated positive integers, (the length of sequence ) and (the upper bound on answer ), respectively.
The second line contains space-separated positive integers describing the respective elements in sequence (i.e., ).

Constraints

Output Format

Print a single, non-negative integer denoting the value of (i.e., the maximum integer such that is awesome). As is evenly divisible by any , the answer will always exist.

Sample Input 0

3 5
2 6 4

Sample Output 0

4

Explanation 0

The only common positive divisor of , , and that is is , and we need to find such that . We know because would not evenly divide . When we look at the next possible value, , we find that this is valid because it's evenly divisible by our value. Thus, we print .

Sample Input 1

1 5
7

Sample Output 1

0

Explanation 1

Being prime, is the only possible value of . The only possible such that is (recall that ), so we print as our answer.

Author

gorbunovdv

Difficulty

Medium

Max Score

30

Submitted By

1877

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website