forked from Twiggecode/Integer-Sequences
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUntouchable Numbers.cpp
56 lines (49 loc) · 1.08 KB
/
Untouchable Numbers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;
// Function to calculate sum of
// all proper divisors of num
int divSum(int num)
{
// Final result of summation
// of divisors
int result = 0;
// Find all divisors of num
for (int i = 2; i <= sqrt(num); i++) {
// If 'i' is divisor of 'num'
if (num % i == 0) {
// If both divisors are same
// then add it only once else
// add both
if (i == (num / i))
result += i;
else
result += (i + num / i);
}
}
// Add 1 to the result as
// 1 is also a divisor
return (result + 1);
}
// Function to check if N is a
// Untouchable Number
bool isUntouchable(int n)
{
for (int i = 1; i <= 2 * n; i++) {
if (divSum(i) == n)
return false;
}
return true;
}
// Driver Code
int main()
{
// Given Number N
int N;
cin >> N;
for (int i =0; i < N; i++){
// Function Call
if (isUntouchable(n))
cout << i << end;
}
}