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

24703번 - Lucky Tickets 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB108675.000%

문제

The government plans a transport reform which will change ticket numbers. The new ticket numbers will consist of $q$ digits in $n$-ary number system, where $q$ is a prime number. Leading zeros are allowed.

A ticket is considered lucky if the product of all its digits added to the sum of all its digits, taken modulo $n,ドル equals $s$. Additionally, every lucky ticket has a degree of luckiness: the degree of luckiness of the ticket with digits $a_1 a_2 \ldots a_q$ equals $$(a_1 + 1) (a_2 + 2) \ldots (a_q + q) + 2^0 a_1 + 2^1 a_2 + \ldots + 2^{q-1} a_q\text{.}$$

For reform report, it is needed to calculate the sum of luckiness of all lucky tickets modulo $q$.

입력

The first line contains three integers $n,ドル $s$ and $q$ (2ドル \le n \le 10^6,ドル 0ドル \le s < n,ドル 2ドル \le q \le 10^6,ドル $q$ is prime).

출력

Print the sum of luckiness of all lucky tickets modulo $q$.

제한

예제 입력 1

2 0 2

예제 출력 1

0

예제 입력 2

10 9 2

예제 출력 2

1

예제 입력 3

3 2 3

예제 출력 3

2

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2022 > Day 5: Yandex Cup H번

Contest > Open Cup > 2021/2022 Season > Stage 12: Grand Prix of Grushevka H번

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

출처

대학교 대회

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

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