daily pastebin goal
27%
SHARE
TWEET

Untitled

a guest Jan 14th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int func (int k, int n)
  5.  {
  6.     int rez = 1;
  7.     if (n==0) {
  8.         return 1;
  9.      } else if (n % 2 == 0) {
  10.         rez = func(k, n/2);
  11.         return rez*rez;
  12.      }  else {
  13.         rez = func(k, (n-1)/2);
  14.         return k*rez;
  15.      }
  16. }
  17.  
  18. int func_m (int k, int n, int m_)
  19.  {
  20.     int rez = 1;
  21.     if (n==0) {
  22.         return 1;
  23.      } else if (n % 2 == 0) {
  24.         rez = func_m(k, n/2, m_);
  25.         return (rez*rez) % m_;
  26.      }  else {
  27.         rez = func_m(k, n-1,m_);
  28.         return (k*rez) % m_;
  29.      }
  30. }
  31. int main(void)
  32. {
  33.     int a, b, c, m;
  34.     scanf("%d%d%d%d", &a, &b, &c, &m);
  35.     int max=func_m(c, func(b, a), m);
  36.     if ((func_m(c,func(a,b), m))>max) max=func_m(c,func(a,b), m);
  37.     if ((func_m(a,func(b,c), m))>max) max=func_m(a,func(b,c), m);
  38.     if ((func_m(a,func(c,b), m))>max) max=func_m(a,func(c,b), m);
  39.     if ((func_m(b,func(a,c), m))>max) max=func_m(b,func(a,c), m);
  40.     if ((func_m(b,func(c,a), m))>max) max=func_m(b,func(c,a), m);
  41.     printf("%d\n", max);
  42.     return 0;
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top