Answers for "how to find number of divisors of any number in O(1) time complexity"

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

Code answers related to "how to find number of divisors of any number in O(1) time complexity"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language