You are viewing a single comment's thread. Return to all comments →
When talking about math, it only requires to loop from 1 to sqrt(n):
public int divisor_sum(int n){ int sum=0; int sqrt = (int)Math.sqrt(n); for (int i=1; i<=sqrt; i++) if (n%i==0) sum = sum + i + n/i; if (n == sqrt*sqrt) sum = sum-sqrt; return sum; }
Java Interface
You are viewing a single comment's thread. Return to all comments →
When talking about math, it only requires to loop from 1 to sqrt(n):