F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

discrete logarithm problem

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 467    Accepted Submission(s): 192


Problem Description
You are given three integers $p, a, b$, where $p$ is a prime number and $p-1$ only has prime factors $2$ and/or $3$. Please find the minimum positive integer $x$ such that $a^x \equiv b \pmod{p}$.
 

Input
The first line contains an integer $T$ indicating there are $T$ tests. Each test consists of a single line containing three integers: $p, a, b$.

* $T \le 200$

* $65537 \le p \le 10^{18}$

* the prime factors of $p-1$ can only be $2$ or $3$

* $2 \le a, b \le p-1$
 

Output
For each test, output a line containing an integer $x$, representing the minimum positive value such that $a^x \equiv b \pmod{p}$. If there didn't exist any such number $x$, please output $-1$.
 

Sample Input
6 65537 2 3 65537 2 4 65537 3 4 65537 4 4 65537 5 4 666334875701477377 2 3
 

Sample Output
-1 2 45056 1 36864 1957714645490451
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-25 05:38:47, Gzip enabled