/home/toolbox/public_html/solutions/3/374/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: 2021-11-11
21 * Purpose: fun
22 * Problem: 374 - Big Mod
23 */
24
25 /*
26 * This template reads lines of data at a time until end of file.
27 */
28
29 unsigned int b;
30 unsigned int p;
31 unsigned int m;
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 = (1 == scanf(" %u ", &b));
49 if (dataReadFlag)
50 {
51 /* more to read ? */
52 scanf(" %u %u ", &p, &m);
53 } /* more to read ? */
54 return (dataReadFlag);
55 } /* FUNCTION getInput */
56
57 void process()
58 {
59 /* FUNCTION process */
60 unsigned int i;
61 unsigned int goal;
62
63 b = b % m;
64 goal = b;
65 for (i=1; p>i; i++)
66 {
67 /* for each power */
68 goal = ((goal * b) % m);
69 } /* for each power */
70 printf("%u\n", goal);
71 } /* FUNCTION process */
72
73 int main()
74 {
75 /* main */
76 int moreToDo;
77
78 init();
79 moreToDo = getInput();
80 while (moreToDo)
81 {
82 /* while */
83 process();
84 moreToDo = getInput();
85 } /* while */
86
87 return EXIT_SUCCESS;
88 } /* main */
89