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.
I didn't find a single proper solution or even hint in discussion, so I wrote this.
hint:If factor of f divides an unfriendly number, then factor of f also divides gcd(unfriendly number, f)
Solution in python:
importmath[n,f]=list(map(lambdax:int(x),input().split()))l=list(map(lambdax:int(x),input().split()))#sets to hold gcds and factorsgcds=set()factors=set()#find gcds of f and each unfriendly numberforiinl:gcds.add(math.gcd(i,f))#find factors of fforiinrange(1,math.ceil(math.sqrt(f))):iff%i==0:factors.add(i)factors.add(f//i)# keeps count of number of factors not dividing unfriendly numbersans=0#find those numbersforiinfactors:forjingcds:ifj%i==0:breakelse:continueelse:ans+=1print(ans)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Unfriendly Numbers
You are viewing a single comment's thread. Return to all comments →
Full Solution in Python:
I didn't find a single proper solution or even hint in discussion, so I wrote this.
hint: If factor of f divides an unfriendly number, then factor of f also divides gcd(unfriendly number, f)
Solution in python: