QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 256 MB Total points: 100

#969. Dyskretny logarytm to żart

Statistics

Niech $M = 10^{18} + 31$, co jest liczbą pierwszą, oraz $g = 42$, co jest pierwiastkiem pierwotnym modulo $M$. Oznacza to, że $g^1 \pmod M, g^2 \pmod M, \dots, g^{M-1} \pmod M$ są wszystkimi różnymi liczbami całkowitymi z przedziału $[1; M)$. Zdefiniujmy funkcję $f(x)$ jako najmniejszą dodatnią liczbę całkowitą $p$ taką, że $g^p \equiv x \pmod M$. Łatwo zauważyć, że $f$ jest bijekcją z $[1; M)$ na $[1; M)$.

Zdefiniujmy ciąg liczb w następujący sposób:

  • $a_0 = 960\,002\,411\,612\,632\,915$ (tę liczbę można skopiować z przykładu);
  • $a_{i+1} = f(a_i)$.

Dla danego $n$ znajdź $a_n$.

Wejście

Jedyna linia wejścia zawiera jedną liczbę całkowitą $n$ ($0 \le n \le 10^6$).

Wyjście

Wypisz $a_n$.

Przykład

Wejście 1

0

Wyjście 1

960002411612632915

Wejście 2

1

Wyjście 2

836174947389522544

Wejście 3

300300

Wyjście 3

263358264583736303

Wejście 4

1000000

Wyjście 4

300

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.