아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Exponentiation

면접 대비

시간 제한3초메모리 제한1024 MB

요약
x + 1/x = alpha일 때 x^beta + 1/x^beta를 m으로 나눈 나머지를 구한다. 이 값은 체비쇼프 점화식을 따른다.
난이도

보통10점 중 5점

유형
수학, 재귀, 분할 정복, 비트 연산
정답자
아직 제출이 없습니다

문제

Exponentiation is a mathematical operation that involves raising a base number to a certain exponent to obtain a result. In the expression ana^n, where aa is the base and nn is the exponent, it means multiplying aa by itself nn times. The result of this operation is called the exponentiation of aa to the nn-th power. For examples, 23=2×2×2=82^3=2 \times 2 \times 2=8 and 52=5×5=255^2=5 \times 5=25. In these examples, 22 is the base, 33 is the exponent in the first case, and 55 is the base, and 22 is the exponent in the second case. Exponentiation is a fundamental operation in mathematics and is commonly used in various contexts, such as solving equations, and cryptography.

In many cryptographic algorithms, particularly those based on number theory like RSA (Rivest-Shamir-Adleman) and Diffie-Hellman, modular exponentiation is a fundamental operation. Modular exponentiation involves raising a base to an exponent modulo a modulus. This operation is computationally intensive but relatively easy to perform, even for very large numbers.

Let x+1x=αx+\frac{1}{x}= \alpha where α\alpha is a positive integer. Please write a program to compute xβ+1xβ mod mx^\beta + \frac{1}{x^\beta} \bmod m for given positive integers β\beta and mm.

입력

The input has only one line, and it contains three space-separated positive integers α\alpha, β\beta and mm. α\alpha, β\beta and mm are positive integers less than 2642^{64}.

출력

Outout xβ+1xβ mod mx^\beta + \frac{1}{x^\beta} \bmod m. You may assume xβ+1xβx^\beta + \frac{1}{x^\beta} is an integer. If there are multiple solutions, you may output any of them in the range from 00 to m−1m-1.

힌트

xx can be a complex number. For example, xx is either 1+3i2\frac{1 + \sqrt{3}i}{2} or 1−3i2\frac{1 - \sqrt{3}i}{2} if α=1\alpha=1. However, xβ+1xβx^\beta + \frac{1}{x^\beta} is always an integer in this problem.

예제4

  1. 예제 1

    입력
    1 2 3
    
    예상 출력
    2
    
  2. 예제 2

    입력
    5 4 321
    
    예상 출력
    206
    
  3. 예제 3

    입력
    3 3 333
    
    예상 출력
    18
    
  4. 예제 4

    입력
    8 8 888
    
    예상 출력
    626