find divisors

//input
int N;
//output
List divisors = new ArrayList<>();

//counter
int c = 2;
//find divisors of N
while(c <= Math.sqrt(N)) {
    if(N % c == 0) {
        divisors.add(N);
        if(c != (N / c)) {
            divisors.add(N/c);
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *