• + 0 comments

    TypeScript

    interface AdvancedArithmetic {
        divisorSum(n: number): number;
    }
    
    class Calculator implements AdvancedArithmetic {
        divisorSum(n: number): number {
            let sum = 0;
            for (let i = 1; i <= n; i++) {
                if (n % i === 0) {
                    sum += i;
                }
            }
            return sum;
        }
    }
    
    function main() {
       let n: number = parseInt(readLine(), 10);
       const myCalculator: AdvancedArithmetic = new Calculator(); 
       const sum = myCalculator.divisorSum(n);
    
        const interfaceName = "AdvancedArithmetic";
       console.log("I implemented: " + interfaceName);
       console.log(sum);
    }