UVALive 7457 Discrete Logarithm Problem (暴力枚举)
Discrete Logarithm Problem
题目链接:
http://acm.hust.edu.cn/vjudge/contest/127401#problem/D
Description
http://7xjob4.com1.z0.glb.clouddn.com/42600d1bedc3c308a68ea0453befd84eInput
The first line of the input file contains a prime p, 1 < p < 2^13 . This prime will be used in the following test cases. Each test case contains two integers a and b in a line. The last test case is followed by a line containing ‘0’.Output
For each test case, print out the solution x to the equation a x = b in the finite group Zp. If there are no solutions, print ‘0’.Sample Input
31 24 3 3 15 0Sample Output
7 21##题意: 求一个x使得 a^x%p = b .
##题解: 由于p的规模巨小(2^13),而取模的结果一定在p次以内出现循环,所以直接从0~p枚举x即可. 很多人TLE了,不知道什么姿势. (可能是末尾的0没有读好) 虽然是水题,还是很高兴拿了FB.
##代码: ``` cpp #include