![]() |
VOOZH | about |
Given four integers A, B, K, M. The task is to find (A + iB)K % M which is a complex number too. A + iB represents a complex number. Examples:
Input : A = 2, B = 3, K = 4, M = 5 Output: 1 + i*0 Input : A = 7, B = 3, K = 10, M = 97 Output: 25 + i*29
Prerequisite: Modular Exponentiation Approach: An efficient approach is similar to the modular exponentiation of a single number. Here, instead of a single we have two number A, B. So, pass a pair of integers as a parameter to the function instead of a single number. Below is the implementation of the above approach :
25 + i29
Time complexity: O(log k).
Auxiliary Space: O(1)