/home/toolbox/public_html/solutions/101/10190/al.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 MAX_LINE 257
16
17 /*
18 * Author: Isaac Traxler
19 * Date: 2021-01-14
20 * Purpose: fun
21 * Problem: 10190 - Divide, But Not Quite Conquer!
22 */
23
24 /*
25 * This template reads lines of data at a time until end of file.
26 */
27
28 long n;
29 long m;
30 long buf[50];
31 int cnt;
32
33 void init()
34 {
35 /* FUNCTION init */
36 } /* FUNCTION init */
37
38 void dump()
39 {
40 /* FUNCTION dump */
41 } /* FUNCTION dump */
42
43 int getInput()
44 {
45 /* FUNCTION getInput */
46 int dataReadFlag;
47
48 dataReadFlag = (2 == scanf(" %ld %ld ", &n, &m));
49 return (dataReadFlag);
50 } /* FUNCTION getInput */
51
52 void process()
53 {
54 /* FUNCTION process */
55 long tmp;
56 int valid = TRUE;
57 int i;
58
59 tmp = n;
60 if ((n < m) || (2 > n) || (2 > m))
61 {
62 /* bad case */
63 printf("Boring!\n");
64 } /* bad case */
65 else
66 {
67 /* normal cases */
68 cnt = 0;
69 while ((valid) && (tmp > m))
70 {
71 /* while */
72 tmp = tmp / m;
73 buf[cnt] = tmp;
74 cnt++;
75 valid = 0 == (tmp % m);
76 } /* while */
77 if (valid)
78 {
79 /* valid */
80 printf("%ld ", n);
81 for (i=0; cnt>i; i++)
82 {
83 /* for */
84 printf("%ld ", buf[i]);
85 } /* for */
86 printf("1\n");
87 } /* valid */
88 else
89 {
90 /* invalid */
91 printf("Boring!\n");
92 } /* invalid */
93 } /* normal cases */
94 } /* FUNCTION process */
95
96 int main()
97 {
98 /* main */
99 int moreToDo;
100
101 init();
102 moreToDo = getInput();
103 while (moreToDo)
104 {
105 /* while */
106 process();
107 moreToDo = getInput();
108 } /* while */
109 return EXIT_SUCCESS;
110 } /* main */
111