SOLVE

LATER

Euler's Exponents

Problem

Editorial

Analytics

Given four numbers $$A$$ , $$B$$ , $$C$$ and $$P$$ where $$P$$ is prime number .

where $$phi(P)$$ is the Euler's Totient Function of $$P$$ .

However the equation is restricted only to the prime numbers.

Write a program to solve this problem if the given $$P$$ is not $$Prime$$ .

**Input Format**

First line of input contains a single integer $$T$$ denoting the number of test cases. First and the only line of each test case contains four space separated $$A$$ , $$B$$ , $$C$$ and $$P$$.

**Output Format**

For each test case , Print the required answer .

**Input Constraint**

$$1 ≤ T ≤ 10$$

$$1 ≤ A ≤ 10^9$$

$$1 ≤ B ≤ 10^9$$

$$1 ≤ C ≤ 10^5$$

$$1 ≤ P ≤ 10$$^{$$18$$}

Explanation

Test 1 : A = 3 B = 3 C = 3 P = 777 (A^(B^C)) %P = 258 Test 2 : A = 3 B = 5 C = 2 P = 10 (A^(B^C)) %P = 3

Time Limit:
1.0 sec(s)
for each input file.

Memory Limit:
256 MB

Source Limit:
1024 KB

Marking Scheme:
Marks are awarded when all the testcases pass.

Allowed Languages:
C,
C++,
C++14,
Clojure,
C#,
D,
Erlang,
F#,
Go,
Groovy,
Haskell,
Java,
Java 8,
JavaScript(Rhino),
JavaScript(Node.js),
Julia,
Lisp,
Lisp (SBCL),
Lua,
Objective-C,
OCaml,
Octave,
Pascal,
Perl,
PHP,
Python,
Python 3,
R(RScript),
Racket,
Ruby,
Rust,
Scala,
Swift,
Visual Basic,
Kotlin

Initializing Code Editor...

OTHER PROBLEMS OF THIS CHALLENGE

{"978fba1": "/pagelets/problem-author-tester/algorithm/eulers-exponents-23/", "978fb89": "/pagelets/suggested-problems/algorithm/eulers-exponents-23/", "978fb62": "/pagelets/show-submission/algorithm/eulers-exponents-23/", "978fbb7": "/pagelets/problems-hint/algorithm/eulers-exponents-23/", "978fbcc": "/pagelets/recommended-problems/algorithm/eulers-exponents-23/"}

{}

realtime.hackerearth.com

80

66e47f523a6a59be7be212c57c843e072bcc8b8a

58a29e5cae2309f04b28

/realtime/pusher/auth/