-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path4-2-9.c
47 lines (34 loc) · 749 Bytes
/
4-2-9.c
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
#include<stdio.h>
int isNarcissus(int number, int N);
int main() {
int N;
scanf("%d", &N);
int start = 1, end = 1;;
for (int i = 0; i < N - 1; i++)
start *= 10;
end = start * 10 - 1;
if (N >= 3 && N <= 7) {
for (int i = start; i <= end; i++) {
if (isNarcissus(i, N)) {
printf("%d\n", i);
}
}
}
return 0;
}
int isNarcissus(int number, int N) {
int item;
int Num = number;
for (int i = 0; i < N; i++) {
item = number % 10;
number /= 10;
int temp = item;
for (int j = 1; j < N; j++) {
item *= temp;
}
Num -= item;
}
if (0 == Num)
return 1;
return 0;
}