File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .math .*;
3+
4+ // Function to calculate sum of divisors
5+ class GFG {
6+ static int getSum (int n )
7+ {
8+ int sum = 0 ;
9+
10+ // Note that this loop runs till square
11+ // root of n
12+ for (int i =1 ; i <=(Math .sqrt (n )); i ++)
13+ {
14+ if (n %i ==0 )
15+ {
16+ // If divisors are equal,take only
17+ // one of them
18+ if (n /i == i )
19+ sum = sum + i ;
20+
21+ else // Otherwise take both
22+ {
23+ sum = sum + i ;
24+ sum = sum + (n / i );
25+ }
26+ }
27+ }
28+
29+ // calculate sum of all proper divisors
30+ // only
31+ sum = sum - n ;
32+ return sum ;
33+ }
34+
35+ // Function to check Abundant Number
36+ static boolean checkAbundant (int n )
37+ {
38+ // Return true if sum of divisors is
39+ // greater than n.
40+ return (getSum (n ) > n );
41+ }
42+
43+ /* Driver program to test above function */
44+ public static void main (String args [])throws
45+ IOException
46+ {
47+ if (checkAbundant (12 ))
48+ System .out .println ("YES" );
49+ else
50+ System .out .println ("NO" );
51+ if (checkAbundant (15 ))
52+ System .out .println ("YES" );
53+ else
54+ System .out .println ("NO" );
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments