Skip to main content

Number Theory and Binary Search

Description

Editorial

caution

Don’t read the editorial, if you have not attempted or read the problems. It would hamper your thinking capability, if you do so.

A. Find xF(n)x^{F(n)} mod m

Given 3 positive integers - xx, nn and mm. Find value of xF(n)x^{F(n)} mod mm .
The function F(n)F(n) is defined as the product of square of primes up to nn (inclusive).
For eg. F(5)=223252=900F(5) = 2^2 \cdot 3^2 \cdot 5^2 = 900 .

Constraints

  • 1x,m1091 \leq x,m \leq 10^9
  • 2n1062 \leq n \leq 10^6