import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int number;
Scanner input = new Scanner(System.in);
System.out.println("Enter a number:");
number = input.nextInt();
int max = (int) Math.sqrt(number);
int sum = 1;
for (int i=2; i <= max; i++)
{
if (number % i == 0)
{
sum += i;
int divisors = number/i;
if (divisors != i) sum += divisors;
}
}
System.out.println(sum);
}
}
Calculate the sum of divisors of a number
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.