Logo
(追記) (追記ここまで)

30323번 - Exponentiation 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 (추가 시간 없음) 1024 MB4271208931.228%

문제

Exponentiation is a mathematical operation that involves raising a base number to a certain exponent to obtain a result. In the expression $a^n,ドル where $a$ is the base and $n$ is the exponent, it means multiplying $a$ by itself $n$ times. The result of this operation is called the exponentiation of $a$ to the $n$-th power. For examples, 2ドル^3=2 \times 2 \times 2=8$ and 5ドル^2=5 \times 5=25$. In these examples, 2ドル$ is the base, 3ドル$ is the exponent in the first case, and 5ドル$ is the base, and 2ドル$ 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+\frac{1}{x}= \alpha$ where $\alpha$ is a positive integer. Please write a program to compute $x^\beta + \frac{1}{x^\beta} \bmod m$ for given positive integers $\beta$ and $m$.

입력

The input has only one line, and it contains three space-separated positive integers $\alpha,ドル $\beta$ and $m$. $\alpha,ドル $\beta$ and $m$ are positive integers less than 2ドル^{64}$.

출력

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

제한

예제 입력 1

1 2 3

예제 출력 1

2

예제 입력 2

5 4 321

예제 출력 2

206

예제 입력 3

3 3 333

예제 출력 3

18

예제 입력 4

8 8 888

예제 출력 4

626

노트

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

출처

ICPC > Regionals > Asia Pacific > Taiwan > Taiwan Online Programming Contest > TOPC 2023 E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /