Computer Programming Contest Preparation

ToolBox - Source for: 12/1243/a.c



/home/toolbox/public_html/solutions/12/1243/a.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 long long x;
   31 long long 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(" %lld %lld %d ", &x, &y, &n);
   49 } /* FUNCTION getInput */
   50 
   51 long long modPow(long long x, long long y, int z)
   52 {
   53     /* FUNCTION modPow */
   54     long long p;
   55     long long 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     long long tmp;
   72     tmp = modPow(x, y, n);
   73     printf("%lld\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