Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
685 B
2
Indexable
Never
package com.company;

import java.util.*;

interface AdvancedArithmetic{
    int divisorSum(int n);
}

class MyCalculator implements AdvancedArithmetic{
    public int divisorSum(int n){
        int sum=1;
        for(int i=2;i<=(n/2);i++){
            if(n%i==0)sum+=i;
        }
        if(n!=1)
            return sum+n;
        else
            return sum;
    }
}
class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        
        AdvancedArithmetic obj =new MyCalculator();
        
        int sum=obj.divisorSum(n);
        System.out.println("Total =" + sum);
    }
}