There's nothing to say ...
---------------------------------------------------------------------
#include <cstdio>#include <cmath>#include <map>using namespace std;typedef long Long ll;int MOD; void gcd (int a, int b, int& D, int& x, int& y) {if (!b) {d = A;x = 1;y = 0;} else {gcd (b, a% B, D, y, x);Y-= x * (A/b);}}//x^t% MODint Power (int x, int t) {int ret = 1;for (; t; t >>= 1) {if (T & 1) ret = LL (x) * ret% MOD;x = LL (x) * x% MOD;}return ret;}//a^x = b (mod mod)int bsgs (int a, int b) {if (a% MOD = = 0) return-1;int m = sqrt (MOD + 0.5), E = 1, v = Power (A, mod-m-1);Map<int, int> x;x[1] = 0;for (int i = 1; i < m; i++) {e = LL (e) * a% MOD;if (!x.count (e)) x[e] = i;}for (int i = 0; i < m; i++) {if (X.count (b)) return I * m + x[b];B = LL (b) * v% MOD;}return-1;}int main () {int T, K; scanf ("%d%d", &t, &k);While (t--) {int A, b;scanf ("%d%d%d", &a, &b, &mod);if (K = = 1)printf ("%d\n", Power (A, b));else if (K = = 2) {int d, x, y;gcd (A, MOD, D, X, y);if (b% d! = 0) puts ("Orz, I cannot find x!");Elseprintf ("%d\n", (int) ((ll (x) * b/d% mod + mod)));} else if (K = = 3) {int t = BSGS (A, b);if (~t) printf ("%d\n", t);Elseputs ("Orz, I cannot find x!");}}return 0;}
---------------------------------------------------------------------
2242: [SDOI2011] Calculator Time Limit:Ten Sec Memory Limit:Mb
Submit:2111 Solved:825
[Submit] [Status] [Discuss] Description you are asked to design a calculator to complete the following three tasks: 1, given y,z,p, calculates the value of Y^z Mod p, 2, given Y,z,p, calculates the smallest nonnegative integer satisfying the xy≡z (mod p), 3, given y,z,p, the calculation satisfies y^x≡z (mod p ) is the smallest non-negative integer. Input
The input contains multiple sets of data.
The first line contains two positive integers t,k each representing the number of data groups and the type of inquiry (for all data within a test point, the same type of inquiry). The following lines contain three positive integers per line y,z,p, describing a query. Output for each query, outputs a line of answers. For query Types 2 and 3, if no condition exists, the output is "Orz, I cannot find x!", noting that there is a space between the comma and "I". Sample Input "Sample Input 1"
3 1
2 1 3
2 2 3
2 3 3
"Sample Input 2"
3 2
2 1 3
2 2 3
2 3 3
"Data size and conventions"
For 100% of the data, 1<=y,z,p<=10^9, for prime numbers, 1<=t<=10. Sample Output "Sample Output 1"
2
1
2
"Sample Output 2"
2
1
0
HINT
Source
First round Day1
Bzoj 2242: [SDOI2011] Calculator (Fast Power + extended Euclidean + bsgs)