Superperfect Number | Java program to check whether number is superperfect or not ; Function to calculate sum of all divisors ; Final result of summation of divisors ; find all divisors which divides ' num ' ; if ' i ' is divisor of ' num ' ; if both divisors are same then add it only once else add both ; Returns true if n is Super Perfect else false . ; Find the sum of all divisors of number n ; Again find the sum of all divisors of n1 and check if sum is equal to n1 ; Driver code
public class Divisors { static int divSum ( int num ) { int result = 0 ; for ( int i = 1 ; i * i <= num ; ++ i ) { if ( num % i == 0 ) { if ( i == ( num / i ) ) result += i ; else result += ( i + num / i ) ; } } return result ; } static boolean isSuperPerfect ( int n ) { int n1 = divSum ( n ) ; return ( 2 * n == divSum ( n1 ) ) ; } public static void main ( String [ ] args ) { int n = 16 ; System . out . printf ( ( isSuperPerfect ( n ) ? "Yes " ▁ : ▁ " No ")); n = 6 ; System . out . printf ( ( isSuperPerfect ( n ) ? "Yes " ▁ : ▁ " No ")); } }