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.
importmathdefisPrime(n):#Cornercasesif(n<=1):returnFalseif(n<=3):returnTrue# This is checked so that we can skip # middle five numbers in below loop if(n%2==0orn%3==0):returnFalsei=5while(i*i<=n):if(n%i==0orn%(i+2)==0):returnFalsei=i+6returnTruen,l=map(int,input().split())li=list(map(int,input().split()))else:if(n==1):print(0)else:abc=li[0]foriinrange(1,len(li)):abc=math.gcd(abc,li[i])if(l<abc):if(isPrime(abc)):print(0)else:foriinrange(l,1,-1):ans2=math.gcd(i,abc)if(ans2>1):print(l-l%ans2)breakelse:ans=l%abcans1=l-ansprint(ans1)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Easy GCD
You are viewing a single comment's thread. Return to all comments →