Mai intai trebuie sa te autentifici.
Diferente pentru problema/dlog intre reviziile #3 si #2
Nu exista diferente intre titluri.
Diferente intre continut:
== include(page="template/taskheader" task_id="dlog") ==
h4.Aceastaproblemaestesponsorizata de 'IXIA':http://www.ixiacom.com/
h4. This problem is sponsored by 'IXIA':http://www.ixiacom.com/
Seda un numar naturalprim$P$.Definim$Z{~P~}$cafiind multimeatuturorresturilorposibile $modulo P$, adica${0, 1, 2, ... P - 1}$.Toateoperatiileasupranumerelordin$Z{~P~}$ serealizeaza$modulo P$.Deexemplu, in $Z{~5~}$, $3 * 3 = 4 (9 mod 5)$.
A prime integer $P$ is given. We define $Z{~P~}$ as the set of all possible remainders $modulo P$, that is ${0, 1, 2, ... P - 1}$. Any operation on the numbers of $Z{~P~}$ is done $modulo P$. For example, in $Z{~5~}$, $3 * 3 = 4 (9 mod 5)$.
Spunemdespreun numarnatural $G$,dinmultimea${1, 2, ... P - 1}$caestegeneratorallui$Z{~P~}$cuinmultireadaca,ridicandu-llaanumite puteri,putemobtinetoatenumereledin $Z{~P~} \ {0}$.Deexemplu,$2$estegeneratorallui$Z{~5~}$,deoarece: $2^1^ = 2, 2^2^ = 4, 2^3^ = 3, 2^4^ = 1$ (toateoperatiile suntrealizate $modulo 5$).Pedealta parte, $2$nu esteun generator allui$Z{~7~}$,deoarecenu se poate obtinenumarul$5$prinoperatiadescrisa.
We call a natural number $G$, belonging to the set ${1, 2, ... P - 1}$, a generator of $Z{~P~}$ with regard to multiplying if by raising it to some powers we can obtain any number in $Z{~P~} \ {0}$. For example $2$ is a generator of $Z{~5~}$, because: $2^1^ = 2, 2^2^ = 4, 2^3^ = 3, 2^4^ = 1$ (all operations are made $modulo 5$). For $Z{~7~}$, however, $2$ is not a generator as $5$ cannot be obtained through the operation described.
Dandu-seunnumarprim$P$, unnumar $G$, generatorallui$Z{~P~}$,si un numar $Y$apartinandmultimii${1, 2, 3, ... P - 1}$,sasegaseasca$X$minim, cu proprietateaca $G^X^ = Y (mod P)$.
Given a prime number $P$, a generator $G$ of $Z{~P~}$ and a number $Y$ belonging to the set ${1, 2, 3, ... P - 1}$ you must find the minimum $X$ with the property that $G^X^ = Y (mod P)$.
h2.Date de intrare
h2. Input
Fişieruldeintrare $dlog.in$vacontinepeprimalinie$T$,numarulde query-uridinfisierul deintrare.Pe fiecaredintre urmatoarele $T$ linii seva gasicateun query,in formatul$P, G, Y$,cu semnificatiademaisus.
The input file $dlog.in$ contains on its first line a natural number $T$ representing the number of queries in the input file. Each of the next $T$ lines contains one query in the format $P, G, Y$ according to the description above.
h2.Date de ieşire
h2. Output
Fişieruldeieşire$dlog.out$vacontineraspunsurile lacele $T$ query-uri,pelinii separate.
The output file $dlog.out$ must contain $T$ lines. The $i-th$ line will contain the answer to the $i-th$ query in the input file.
h2. Restricţii
h2. Restrictions
* $1 ≤ T ≤ 1.000$ * $2 ≤ P ≤ 2.000.000$ * $1 ≤ G, Y < P$
* **Pentrufiecaredintrecele$T$teste,raspunsultrebuiesa se regaseascain intevalul$[0 .. P - 1]$**
* **The result printed for each test should be in the interval $[0 .. P - 1]$**
h2. Exemplu
h2. Example
table(example). |_. dlog.in |_. dlog.out | |3
4 |
h3.Explicaţie
h3. Sample test explanation
$2^0 MOD 3 = 1 MOD 3 = 1$ $3^3 MOD 5 = 27 MOD 5 = 2$
