## Algorithm

Problem Name: 30 days of code - Day 19: Interfaces

Objective
Today, we're learning about Interfaces. Check out the Tutorial tab for learning materials and an instructional video!

The `AdvancedArithmetic` interface and the method declaration for the abstract `divisorSum(n)` method are provided for you in the editor below.

Complete the implementation of `Calculator` class, which implements the `AdvancedArithmetic` interface. The implementation for the `divisorSum(n)` method must return the sum of all divisors of n.

Example

n = 25

The divisors of 25 are 1,5,25. Their sum is 31.

n = 20

The divisors of 20 are 1,2,4,5,10,20 and their sum is 42.

Input Format

A single line with an integer, n.

Constraints

• n <= n <= 1000

Output Format

You are not responsible for printing anything to stdout. The locked template code in the editor below will call your code and print the necessary output.

Sample Input

``````6
``````

Sample Output

``````I implemented: AdvancedArithmetic
12
``````

## Code Examples

### #1 Code Example with C++ Programming

```Code - C++ Programming```

``````
#include <iostream>

using namespace std;

public:
virtual int divisorSum(int n)=0;
};

class Calculator : public AdvancedArithmetic {
public:
int divisorSum(int n) {
int sum = 0;
for (int i = 1; i <= n; i++)
if (n % i == 0) sum += i;
return sum;
}
};

int main() {
int n;
cin >> n;
int sum = myCalculator->divisorSum(n);
cout << "I implemented: AdvancedArithmetic\n" << sum;
return 0;
}
``````
Copy The Code &

### #2 Code Example with C# Programming

```Code - C# Programming```

``````
using System;
int divisorSum(int n);
}

{
public int divisorSum(int n)
{
int sum = 0;
for (int i = 1; i <= n; i++)
{
if (n % i == 0) sum += i;
}

return sum;
}
}

class Solution{
static void Main(string[] args){
int sum = myCalculator.divisorSum(n);
}
}
``````
Copy The Code &

### #3 Code Example with Java Programming

```Code - Java Programming```

``````
import java.util.Scanner;

int divisorSum(int n);
}

@Override
public int divisorSum(int n) {
int sum = 0;
for (int i = 1; i <= n; i++) {
if (n % i == 0) sum += i;
}
return sum;
}
}

class Solution {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.close();

int sum = myCalculator.divisorSum(n);
System.out.println("I implemented: " + myCalculator.getClass().getInterfaces().getName());
System.out.println(sum);
}
}
``````
Copy The Code &

### #4 Code Example with Python Programming

```Code - Python Programming```

``````
def divisorSum(n):
raise NotImplementedError

def divisorSum(self, n):
s = 0
for i in range(1,n+1):
if (n%i == 0):
s+=i
return s

n = int(input())
my_calculator = Calculator()
s = my_calculator.divisorSum(n)
print("I implemented: " + type(my_calculator).__bases__.__name__)
print(s)
``````
Copy The Code &

### #5 Code Example with PHP Programming

```Code - PHP Programming```

``````
divisorSum(\$n);