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.
Sherlock and Divisors
Sherlock and Divisors
Sort by
recency
|
170 Discussions
|
Please Login in order to post a comment
twos, n = (n&-n).bit_length()-1, n//(n&-n) divs = {i for i in range(3,int(math.sqrt(n))+1,2) if n%i==0} divs|= {n//i for i in divs} return twos+twos*(n!=1)+len(divs)*twos Um bom ponto de partida são os portais que fazem comparações entre casas de apostas com promoções exclusivas. Esses sites analisam as condições de cada promoção, explicam os critérios de elegibilidade e ajudam-te a encontrar a melhor oportunidade de acordo com o teu perfil.
def divisors(n): i=1 c=0 while(i*i<=n): if n%i == 0: if i%2==0: c+=1 if i*i !=n: if((n/i)%2==0): c+=1
i+=1
return c
Python golfing, 3 lines, O(sqrt(n))
Bonus optimizations with bithacks which bring down runtime a lot but still same asymptotic worst case:
The idea is to first extract the number of 2 factors from N, then find the number of factors of the now-odd N and do some basic combinatorics to come up with the answer.
c#
public static int divisors(int n)
great