Answers for "python find divisors of a number"

1

all devisor of a number java

public static ArrayList<Integer> getDivisors(int n){
        ArrayList<Integer> divisors = new ArrayList<>();
        //without 1 or n
        for (int i = 2; i * i <= n; ++i)
            if (n % i == 0) {
                divisors.add(i);
                if (i != n / i) divisors.add(n / i);
            }
        return divisors;
    }
Posted by: Guest on December-09-2020
0

find all divisors of a number python

def divisorGen(n):
    factors = list(factorGenerator(n))
    nfactors = len(factors)
    f = [0] * nfactors
    while True:
        yield reduce(lambda x, y: x*y, [factors[x][0]**f[x] for x in range(nfactors)], 1)
        i = 0
        while True:
            f[i] += 1
            if f[i] <= factors[i][1]:
                break
            f[i] = 0
            i += 1
            if i >= nfactors:
                return
              
# Excerpt from stackoverflow (:
Posted by: Guest on April-06-2021

Code answers related to "python find divisors of a number"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language