TopcoderArchiveVisit Topcoder
TCO18 Sep 2018
TCO19 SRM 737

SimpleMathProblem

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given four positive integers a,b,c and m. Let x = bc. Calculate and return the following value: (ax mod m).

Definition

Class:
SimpleMathProblem
Method:
calculate
Parameters:
int, int, int, int
Returns:
int
Method signature:
int calculate(int a, int b, int c, int m)
(be sure your method is public)

Constraints

  • a,b,c and m will each be between 1 and 737,373,737, inclusive.

Examples

  1. 1
    1
    1
    737
    Returns: 1
    1^(1^1) modulo 737 is 1.
  2. 3
    7
    3
    123456789
    Returns: 63564408
    First we get that x = 7^3 = 343. Then we compute the answer: (3^x modulo 123456789).
  3. 12
    34
    56
    78
    Returns: 66
  4. 3737373
    7373737
    37373
    737373737
    Returns: 214080347
  5. 2
    10
    10
    1024
    Returns: 0
    2^(10^10) is divisible by 1024, hence the remainder is zero.
  6. 47
    53
    912
    1
    Returns: 0
    Any integer modulo 1 is zero.
Back to all problems