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

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Mathematics
  3. Number Theory
  4. Sherlock and GCD
  5. Discussions

Sherlock and GCD

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics

Sort 222 Discussions, By:

recency

Please Login in order to post a comment

  • asimali72668
    2 months ago+ 0 comments

    The problem here is essentially to identify, given certain constraints, whether there exists a subset of an array � Check here the following rules:

    It must be a non-empty subset ( � ′ A ′ ). There doesn’t exist an integer � x which divides all elements of � ′ A ′ . There are no elements in � ′ A ′ that are equal to another. Let's derive a solution:

    For rule 3, it's evident that all elements in the array � A must be unique for any subset � ′ A ′ to adhere to it. Rule 2 is the most complex condition to validate. However, if we observe, it's impossible for two co-prime numbers to have a common divisor (other than 1). Therefore, the existence of just two co-prime numbers in � A automatically validates condition 2 for any subset In the sample input provided:

    Copy code 3 3 1 2 3 2 2 4 3 5 5 5 For test case 1: [1, 2, 3] contains co-prime numbers (1 and 2, or 1 and 3, or 2 and 3). So, it outputs "YES". For test case 2: [2, 4] does not contain any pair of co-prime numbers. So, it outputs "NO". For test case 3: [5, 5, 5] has duplicate elements. So, it outputs "NO". � ′ A ′ containing them.

    0|
    Permalink
  • skmwarrior
    2 months ago+ 0 comments

    This is something you should know but you first have to create chatgpt account and then login to Chatgpt.

    0|
    Permalink
  • divyanshsharmak1
    6 months ago+ 0 comments

    two numbers can have gcd >1 but it is also possible tha two sets of numbers having gcd >1, when merged together produces gcd 1. so check for whole vector

    0|
    Permalink
  • masrour_abdelkb1
    10 months ago+ 0 comments

    def gcd(a,b): if(b==0):return a else:return gcd(b,a%b)

    def solve(a): # Write your code here p=reduce(gcd,a) if(p==1):return "YES" else:return "NO"

    0|
    Permalink
  • thenewshub0
    11 months ago+ 0 comments

    Uzbekistan-born American actress Milana Vanturb in the God of War Ragnarok. Born to a Jewish parents, Milana debuted as a child actress in three episodes of a US series ER in 1995. Explore Milana Vayntrub bikini, modeling and styling ideas. Visit us for sexy pics of milana vayntrub

    -1|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy