We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
//we could stop at sqrt(n)//This is my Java solution. I think this may be better.classCalculatorimplementsAdvancedArithmetic{publicintdivisorSum(intn){intsum=0;for(inti=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){sum=sum+i+n/i;}}if((int)Math.sqrt(n)*(int)Math.sqrt(n)==n){sum-=Math.sqrt(n);}returnsum;}}
Cookie support is required to access HackerRank
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 →