File tree 1 file changed +62
-0
lines changed
1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .*;
2
+ // Java program for the above approach
3
+ class Main {
4
+
5
+ // Function to calculate sum of
6
+ // all proper divisors of num
7
+ static int divSum (int num )
8
+ {
9
+
10
+ // Final result of summation
11
+ // of divisors
12
+ int result = 0 ;
13
+
14
+ // Find all divisors of num
15
+ for (int i = 2 ; i <= Math .sqrt (num ); i ++)
16
+ {
17
+
18
+ // If 'i' is divisor of 'num'
19
+ if (num % i == 0 )
20
+ {
21
+
22
+ // If both divisors are same
23
+ // then add it only once else
24
+ // add both
25
+ if (i == (num / i ))
26
+ result += i ;
27
+ else
28
+ result += (i + num / i );
29
+ }
30
+ }
31
+
32
+ // Add 1 to the result as
33
+ // 1 is also a divisor
34
+ return (result + 1 );
35
+ }
36
+
37
+ // Function to check if N is a
38
+ // Untouchable Number
39
+ static boolean isUntouchable (int n )
40
+ {
41
+ for (int i = 1 ; i <= 2 * n ; i ++)
42
+ {
43
+ if (divSum (i ) == n )
44
+ return false ;
45
+ }
46
+ return true ;
47
+ }
48
+
49
+ // Driver code
50
+ public static void main (String [] args )
51
+ {
52
+
53
+ // Given Number N
54
+ int n ;
55
+ Scanner sc = new Scanner (System .in );
56
+ n = sc .nextInt ();
57
+ // Function Call
58
+ for (int i =0 ; i <=n ; i ++)
59
+ if (isUntouchable (i ))
60
+ System .out .print (i +" " );
61
+ }
62
+ }
You can’t perform that action at this time.
0 commit comments