You are viewing a single comment's thread. Return to all comments →
My realization of what you suggested:
public int divisorSum(int n) { if (n == 1) return 1; int sum = 0; for (int div = 1; div*div <= n; div++){ sum += n % div == 0 ? div + n / div : 0; } return Math.sqrt(n) % 1 == 0 ? sum - (int) Math.sqrt(n) : sum; }
Seems like cookies are disabled on this browser, please enable them to open this website
Day 19: Interfaces
You are viewing a single comment's thread. Return to all comments →
My realization of what you suggested: