/home/toolbox/public_html/solutions/111/11137/b.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 #include <ctype.h>
10
11 #define TRUE (1 == 1)
12 #define FALSE (1 != 1)
13
14 #define DEBUG if (FALSE)
15
16 #define MAX_LINE 257
17
18 /*
19 * Author: Isaac Traxler
20 * Date: 2022-08-24
21 * Purpose: fun
22 * Problem: 11137 - Ingenuous Cubrency
23 */
24
25 /*
26 * This template reads lines of data at a time until end of file.
27 */
28
29 #define MAX_ARRAY 10649
30 #define MAX_VALUES 10002
31
32 int num;
33 int coins[22] = {1, 8, 27, 64, 125, 216, 343, 512, 729, 1000, 1331, 1728,
34 2187, 2744, 3375, 4096, 4913, 5832, 6859, 8000, 9261, 10648
35 };
36 long long int amounts[MAX_ARRAY];
37
38 int rank(int x)
39 {
40 /* FUNCTION rank */
41 int i;
42
43 while (x > coins[i])
44 {
45 /* while */
46 i++;
47 } /* while */
48 return (i);
49 } /* FUNCTION rank */
50
51 void init()
52 {
53 /* FUNCTION init */
54 int i;
55 long long int cnt;
56 int c;
57 int j;
58 long long int add;
59
60 for (i=1; MAX_VALUES>i; i++)
61 {
62 /* for */
63 amounts[i] = 1;
64 } /* for */
65 for (i=1; 22>i; i++)
66 {
67 /* for each coin */
68 add = 1;
69 cnt = 0;
70 for (j=coins[i]; MAX_VALUES>j; j++)
71 {
72 /* for */
73 amounts[j] = amounts[j] + add;
74 cnt++;
75 if (cnt == coins[i])
76 {
77 /* another time for this coun */
78 cnt = 0;
79 add++;
80 } /* another time for this coun */
81 } /* for */
82 } /* for each coin */
83 DEBUG for (i=1; MAX_VALUES>i; i++)
84 {
85 printf("amounts[%d] = %d\n", i, amounts[i]);
86 }
87 } /* FUNCTION init */
88
89 void dump()
90 {
91 /* FUNCTION dump */
92 } /* FUNCTION dump */
93
94 int getInput()
95 {
96 /* FUNCTION getInput */
97 int dataReadFlag;
98
99 dataReadFlag = (1 == scanf(" %d ", &num));
100 return (dataReadFlag);
101 } /* FUNCTION getInput */
102
103 void process()
104 {
105 /* FUNCTION process */
106 printf("%x\n", amounts[num]);
107 } /* FUNCTION process */
108
109 int main()
110 {
111 /* main */
112 int moreToDo;
113
114 init();
115 moreToDo = getInput();
116 while (moreToDo)
117 {
118 /* while */
119 process();
120 moreToDo = getInput();
121 } /* while */
122
123 return EXIT_SUCCESS;
124 } /* main */
125