/home/toolbox/public_html/solutions/3/324/d.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
11 #define TRUE (1 == 1)
12 #define FALSE (1 != 1)
13
14 #define DEBUG if (FALSE)
15
16 /*
17 * Author: Isaac Traxler
18 * Date: 2021-01-04
19 * Purpose: fun
20 * Problem: 324 - Factorial Frequencies
21 */
22
23 /*
24 * This template reads data until a terminating value is reached.
25 */
26
27 #include "LargeNumber.c"
28
29 #define LN_DIMM 1000
30 #define MAXX 367
31
32 LARGE_NUMBER_STRUCT a;
33 LARGE_NUMBER_STRUCT b;
34 LARGE_NUMBER_STRUCT c;
35 int num;
36 int cach[MAXX][10];
37
38 void dump(int i)
39 {
40 /* FUNCTION dump */
41 int j;
42
43 printf(" (%d) %3d", 0, cach[i][0]);
44 for (j=1; j<5; j++)
45 {
46 /* for each digit */
47 printf(" (%d) %3d", j, cach[i][j]);
48 } /* for each digit */
49 printf("\n");
50 printf(" (%d) %3d", 5, cach[i][5]);
51 for (j=6; j<10; j++)
52 {
53 /* for each digit */
54 printf(" (%d) %3d", j, cach[i][j]);
55 } /* for each digit */
56 printf("\n");
57 } /* FUNCTION dump */
58
59 void init()
60 {
61 /* FUNCTION init */
62 int i;
63 int j;
64 long int x;
65
66 /* manually set 1 */
67 for (j=0; j<10; j++)
68 {
69 /* for each digit */
70 cach[1][j] = 0;
71 } /* for each digit */
72 cach[1][1] = 1;
73 DEBUG dump(1);
74 x = 1;
75 LNicnvrt(x, &b);
76 DEBUG printf("b: ");
77 DEBUG LNprint(&b);
78 /* 2 thru 366 */
79 for (i=2; i<MAXX; i++)
80 {
81 /* for each possible fact */
82 x = i;
83 LNicnvrt(x, &a);
84 DEBUG printf("a: ");
85 DEBUG LNprint(&a);
86 LNmultiply(&a, &b, &c);
87 DEBUG printf("a: ");
88 DEBUG LNprint(&a);
89 DEBUG printf("b: ");
90 DEBUG LNprint(&b);
91 DEBUG printf("c: ");
92 DEBUG LNprint(&c);
93 LNcopy(&c, &b);
94 for (j=0; j<10; j++)
95 {
96 /* for each digit */
97 cach[i][j] = 0;
98 } /* for each digit */
99 DEBUG LNprint(&c);
100 for (j=0; j<c.digitCount; j++)
101 {
102 /* for each digit */
103 cach[i][c.array[j]] = cach[i][c.array[j]] + 1;
104 DEBUG printf("%d", c.array[j]);
105 } /* for each digit */
106 cach[i][0] = cach[i][0] - c.digitCount + c.exponent;
107 DEBUG printf("\n");
108 DEBUG dump(i);
109 } /* for each possible fact */
110 } /* FUNCTION init */
111
112 int getInput()
113 {
114 /* FUNCTION getInput */
115 int dataReadFlag;
116
117 scanf(" %d ", &num);
118 dataReadFlag = (0 < num);
119 return (dataReadFlag);
120 } /* FUNCTION getInput */
121
122 void process()
123 {
124 /* FUNCTION process */
125 printf("%d! --\n", num);
126 dump(num);
127 } /* FUNCTION process */
128
129 int main()
130 {
131 /* main */
132 int moreToDo;
133
134 init();
135 moreToDo = getInput();
136 while (moreToDo)
137 {
138 /* while */
139 process();
140 moreToDo = getInput();
141 } /* while */
142
143 return EXIT_SUCCESS;
144 } /* main */
145