Sort by

recency

|

171 Discussions

|

  • + 0 comments

    Interesting problem! Just like careful planning is needed to count divisors correctly, ensuring smooth pet transportation services requires attention to every small detail.

  • + 0 comments

    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.

  • + 0 comments

    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

  • + 0 comments

    Python golfing, 3 lines, O(sqrt(n))

    divs = {i for i in range(2,int(math.sqrt(n))+1) if n%i==0}
    divs|= {n//i for i in divs}|{n}
    return sum(not i&1 for i in divs)
    

    Bonus optimizations with bithacks which bring down runtime a lot but still same asymptotic worst case:

    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 
    

    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.

  • + 0 comments

    c#

    public static int divisors(int n)

    {
        int divisors = 0;
        if (n % 2 != 0)
        {
            return divisors;
        }
        else for (int i = 1; i <= Math.Floor(Math.Sqrt(n/2)); i++)
        {
            if ((n/2) % i == 0)
            {
                divisors++;
                if (i*i != n/2)
                {
                    divisors++;
                }
            }
        }
        return divisors;
    }