Check if a number is Triperfect Number | Java code to check if a given number is Triperfect or not ; Returns true if n is Triperfect ; To store sum of divisors . Adding 1 and n since they are divisors of n . ; Find all divisors and add them ; If sum of divisors is equal to 3 * n , then n is a Triperfect number ; Driver program
public class GFG { static boolean isTriPerfect ( int n ) { int sum = 1 + n ; int i = 2 ; while ( i * i <= n ) { if ( n % i == 0 ) { if ( n / i == i ) sum = sum + i ; else sum = sum + i + n / i ; } i += 1 ; } if ( sum == 3 * n & n != 1 ) return true ; else return false ; } public static void main ( String [ ] args ) { int n = 120 ; if ( isTriPerfect ( n ) ) System . out . println ( n + " ▁ is ▁ a ▁ Triperfect ▁ number " ) ; } }