/home/toolbox/public_html/solutions/6/640/a.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15 #define UPPER_LIMIT 1000001
16 #define SELF_NUMBER -1
17 #define GENERATOR 1
18
19 /*
20 * Author: Isaac Traxler
21 * Date: 2012-02-10
22 * Purpose: fun
23 * Problem: 640 - self-numbers
24 */
25
26 /*
27 * This template reads data until a terminating value is reached.
28 */
29
30 int ary[UPPER_LIMIT];
31
32 int calc(int a)
33 {
34 /* FUNCTION calc */
35 int tot = 0;
36 int num;
37
38 num = a;
39 while (0 < num)
40 {
41 /* while */
42 tot = tot + (num % 10);
43 num = num / 10;
44 } /* while */
45 return (a + tot);
46 } /* FUNCTION calc */
47
48 void init()
49 {
50 /* FUNCTION init */
51 int i;
52 int tmp;
53
54 for (i=1; i<UPPER_LIMIT; i++)
55 {
56 /* for */
57 ary[i] = SELF_NUMBER;
58 } /* for */
59
60 for (i=1; i<UPPER_LIMIT; i++)
61 {
62 /* for */
63 tmp = calc(i);
64 ary[tmp] = GENERATOR;
65 } /* for */
66 } /* FUNCTION init */
67
68 void process()
69 {
70 /* FUNCTION process */
71 int i;
72
73 for (i=1; i<UPPER_LIMIT; i++)
74 {
75 /* for */
76 if (SELF_NUMBER == ary[i])
77 {
78 /* check the number */
79 printf("%d\n", i);
80 } /* check the number */
81 } /* for */
82 } /* FUNCTION process */
83
84 int main ()
85 {
86 /* main */
87
88 init();
89 process();
90 return EXIT_SUCCESS;
91 } /* main */
92