Clever Y Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 8666 Accepted: 2155 Description Little Y finds there is a very interesting formula in mathematics: XY mod Z = K Given X, Y, Z, we all know how to figure out K fast. However, give…
1467: Pku3243 clever Y Time Limit: 4 Sec Memory Limit: 64 MB[Submit][Status][Discuss] Description 小Y发现,数学中有一个很有趣的式子: X^Y mod Z = K 给出X.Y.Z,我们都知道如何很快的计算K.但是如果给出X.Z.K,你是否知道如何快速的计算Y呢? Input 本题由多组数据(不超过20组),每组测试数据包含一行三个整数X.Z.K(0 <= X, Z, K <= 109). 输入文…
Description Little Y finds there is a very interesting formula in mathematics: XY mod Z = K Given X, Y, Z, we all know how to figure out K fast. However, given X, Z, K, could you figure out Y fast? Input Input data consists of no more than 20 test ca…
Description Little Y finds there is a very interesting formula in mathematics: XY mod Z = K Given X, Y, Z, we all know how to figure out K fast. However, given X, Z, K, could you figure out Y fast? Input Input data consists of no more than 20 test ca…
http://poj.org/problem?id=3243 题意:求$a^y \equiv b \pmod{p}$最小的$y$.(0<=x, y, p<=10^9) #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <iostream> typedef long long ll; using namespace st…
Description Little Y finds there is a very interesting formula in mathematics: XY mod Z = K Given X, Y, Z, we all know how to figure out K fast. However, given X, Z, K, could you figure out Y fast? Input Input data consists of no more than 20 test ca…
1467: Pku3243 clever Y Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 313 Solved: 181[Submit][Status][Discuss] Description 小Y发现,数学中有一个很有趣的式子: X^Y mod Z = K 给出X.Y.Z,我们都知道如何很快的计算K.但是如果给出X.Z.K,你是否知道如何快速的计算Y呢? Input 本题由多组数据(不超过20组),每组测试数据包含一行三个整数X.Z.K(0…
T2 扩展BSGS T3 快速阶乘 给定整数n,质数p和正整数c,求整数s和b,满足n! / pb = s mod pc 考虑每次取出floor(n/p)个p因子,然后将问题转化为子问题. /************************************************************** Problem: 3283 User: idy002 Language: C++ Result: Accepted Time:1704 ms Memory:12380 kb ***…
扩展BSGS用于求解axΞb mod(n) 同余方程中gcd(a,n)≠1的情况 基本思路,将原方程转化为a与n互质的情况后再套用普通的BSGS求解即可 const int maxint=((1<<30)-1)*2+1; struct Hashmap{ static const int Ha=999917,maxe=46340; int E,lnk[Ha],son[maxe+5],nxt[maxe+5],w[maxe+5]; int top,stk[maxe+5]; …
1467: Pku3243 clever Y Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 425 Solved: 238[Submit][Status][Discuss] Description 小Y发现,数学中有一个很有趣的式子: X^Y mod Z = K 给出X.Y.Z,我们都知道如何很快的计算K.但是如果给出X.Z.K,你是否知道如何快速的计算Y呢? Input 本题由多组数据(不超过20组),每组测试数据包含一行三个整数X.Z.K(0…
每次把gcd(a,c)提到前面,直到a,c互质,然后就是普通BSGS了 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #define LL long long using namespace std; struct hashtable{ static const int N=577399; int tot,hash…
Description Little Y finds there is a very interesting formula in mathematics: XY mod Z = K Given X, Y, Z, we all know how to figure out K fast. However, given X, Z, K, could you figure out Y fast? Input Input data consists of no more than 20 test ca…
辗转相除法(欧几里得算法) 时间复杂度:在O(logmax(a, b))以内 int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } 扩展欧几里得算法 时间复杂度和欧几里得算法相同 int extgcd(int a, int b, int& x, int& y) { int d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x;…