2017년 12월 23일 토요일

[C++] HackerRank Day19 Solution

/*

https://www.hackerrank.com/challenges/30-interfaces/problem


*/



class Calculator : public AdvancedArithmetic {
    public:
        int divisorSum(int n){
            int result = 0;
            for(int i=1;(int)i<=n/2;i++){        //Caculate numbers one to n/2
                if(n%i == 0){
                    result += i;
                }
            }
           
            result += n;        //Add n itself.
           
            return result;
        }
   
};

댓글 없음:

댓글 쓰기