/home/toolbox/public_html/solutions/12/1243/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 <stdlib.h>
7 #include <math.h>
8 #include <stdint.h>
9 #include <ctype.h>
10
11 #define TRUE (1 == 1)
12 #define FALSE (1 != 1)
13
14 #define DEBUG if (FALSE)
15
16 /* fprintf(stderr, "functionName: message", varslist); */
17
18 /*
19 * Author: Isaac Traxler
20 * Date: 2023-02-17
21 * Purpose: fun
22 * Problem: 1230 - Modex
23 */
24
25 /*
26 * This template reads data a specified number of times.
27 */
28
29 int numberOfTimes;
30 int x;
31 int y;
32 int n;
33
34 void init()
35 {
36 /* FUNCTION init */
37 scanf("%d ", &numberOfTimes);
38 } /* FUNCTION init */
39
40 void dump()
41 {
42 /* FUNCTION dump */
43 } /* FUNCTION dump */
44
45 void getInput()
46 {
47 /* FUNCTION getInput */
48 scanf(" %d %d %d ", &x, &y, &n);
49 } /* FUNCTION getInput */
50
51 int modPow(int x, int y, int z)
52 {
53 /* FUNCTION modPow */
54 int p;
55 int ret = 1;
56
57 if (0 != y)
58 {
59 /* do calc */
60 p = modPow(x, y / 2, n);
61 ret = p * p % z * (y % 2 ? x : 1) % z;
62 } /* do calc */
63 return ret;
64 } /* FUNCTION modPow */
65
66 void process()
67 {
68 /* FUNCTION process */
69 int i;
70 int cnt;
71 int tmp;
72 tmp = modPow(x, y, n);
73 printf("%d\n", tmp);
74 } /* FUNCTION process */
75
76 int main()
77 {
78 /* main */
79 int i;
80
81 init();
82 for (i=0; i<numberOfTimes; i++)
83 {
84 /* while */
85 getInput();
86 process();
87 } /* while */
88
89 return EXIT_SUCCESS;
90 } /* main */
91
92