포럼
문제 ICPC00240

E. Exponial

설명

Everybody loves big numbers (if you do not, you might want to stop reading at this point). There are many ways of constructing really big numbers known to humankind, for instance:
- Exponentiation: \(42^{2016} = \underbrace{42 \cdot 42 \cdot \ldots \cdot 42}_{2016\text{ times}}\).
- Factorials: $2016! = 2016 \cdot 2015 \cdot
\ldots \cdot 2 \cdot 1$.

In this problem we look at their lesser-known love-child the exponial, which is an operation defined for all positive integers \(n\) as [
\operatorname{exponial}(n) = n{(n-1){(n-2){\cdots.}}}}
] For example, \(\operatorname{exponial}(1) = 1\) and $\operatorname{exponial}(5) =
5{4{3{21}}} \approx 6.206 \cdot 10{183230}\( which\ is\ already\ pretty\ big. Note\ that\ exponentiation\ is\ right-associative: \)a = a{(bc)}$.

Since the exponials are really big, they can be a bit unwieldy to work with. Therefore we would like you to write a program which computes \(\operatorname{exponial}(n) \bmod m\) (the remainder of \(\operatorname{exponial}(n)\) when dividing by \(m\)).

제약
입력 형식

The input consists of two integers \(n\) (\(1 \le n \le 10^9\)) and \(m\) (\(1 \le m \le 10^9\)).

출력 형식

Output a single integer, the value of \(\operatorname{exponial}(n) \bmod m\).

예제 1
입력
2 42
출력
2
예제 2
입력
5 123456789
출력
16317634
예제 3
입력
94 265
출력
39
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NCPC 2016

평가 및 의견

E. Exponial

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

E. Exponial

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8