For those coders out there, I've been playing around with the process of finding the total number of divisors of a number. This probably isn't the most efficient solution, but I found it really entertaining to think about and try to understand:

private static int divisorsofN(long n) { ArrayList<long[]> primeFactorization = new ArrayList<long[]>(); int totalDivisors = 1; for (long l = 2l; l <= n; l++) { if (isPrime(l) && n % l == 0) { boolean hitLimit = false; long[] factorization = new long[2]; factorization[0] = l; while (hitLimit == false) { if (n % l == 0) { factorization[1]++; n /= l; } else { hitLimit = true; } } primeFactorization.add(factorization); } } for (int i = primeFactorization.size() - 1; i >= 0; i--) { totalDivisors *= (primeFactorization.get(i)[1] + 1); } System.out.println(totalDivisors); return totalDivisors; } public static boolean isPrime(long num) { for (long r = 2l; r < num; r++) { if (num % r == 0 && num != 2) { return false; } } return true; }

To understand what's going on here, check out this post: http://mathforum.org...view/55843.html

This could be implemented when faced with a problem such as #12 on Project Euler: https://projecteuler.net/problem=12

I'd love it if anyone came up with more efficient solutions - how could this be improved?

Thanks,

-Yak