污污污污 2242: [SDOI2011]计算器 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 2312 Solved: 917 [Submit][Status][Discuss] Description 你被要求设计一个计算器完成以下三项任务: 1.给定y,z,p,计算Y^Z Mod P 的值: 2.给定y,z,p,计算满足xy≡ Z ( mod P )的最小非负整数: 3.给定y,z,p,计算满足Y^x ≡ Z ( mod P)的最小非负整数…
BSGS算法是meet in the middle思想的一种应用,参考Yveh的博客我学会了BSGS的模版和hash表模板,,, 现在才会hash是不是太弱了,,, #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct node{ static const int mo=100007; int a[100010],v…
1:快速幂  2:exgcd  3:exbsgs,题里说是素数,但我打的普通bsgs就wa,exbsgs就A了...... (map就是慢)..... #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<map> #define LL long long using namespace st…
[bzoj2242]: [SDOI2011]计算器 1.快速幂 2.扩展欧几里得(费马小定理) 3.BSGS /* http://www.cnblogs.com/karl07/ */ #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <map> #include <algorithm> using namespace st…
[bzoj1965]: [Ahoi2005]SHUFFLE 洗牌 观察发现第x张牌 当x<=n/2 x=2x 当x>n/2 x=2x-n-1 好像就是 x=2x mod (n+1)  就好了 /* http://www.cnblogs.com/karl07/ */ #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <algori…
POJ 1845 题意不说了,网上一大堆.此题做了一天,必须要整理一下了. 刚开始用费马小定理做,WA.(poj敢说我代码WA???)(以下代码其实都不严谨,按照数据要求A是可以等于0的,那么结果自然就是0了,需要特判一下,但是poj好像没有为0的数据,能AC.先不改了.) 后来看了好多人的博客,发现很少用费马小定理写的,或者写的代码我看不下去..就先用那个什么二分等比数列写了一下. 过程也不说了,很多博客都说了.([1][2]): #include<iostream> #include<…
Looooops(点击) A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement; I.e., a loop which starts by setting variable to value A and while variable is not equal to B, repeats state…
Power of Fibonacci Time Limit: 5 Seconds      Memory Limit: 65536 KB In mathematics, Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers of the following integer sequence: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, .…
Proper Nutrition 题意:有n元钱,有2种单价不同的商品,是否存在一种购买方式使得钱恰好花光,如果有输入任意一种方式,如果没有输出“NO” 题解:可以使用拓展欧几里得快速求解. #include<iostream> using namespace std; #define ll long long ll gcd(ll a, ll b) { return b? gcd(b, a%b) : a; } void ex_gcd(ll a, ll b, ll &x, ll &…
拉板题,,,不说话 我之前是不是说过数据结构很烦,,,我想收回,,,今天开始的数论还要恶心,一早上听得头都晕了 先来一发欧几里得拓展裸 #include <cstdio> void gcd(int a,int b,int&d,int&x,int&y) { ,y=; else gcd(b,a%b,d,y,x),y-=x*(a/b); } int main() { int a,b,d,x,y; scanf("%d%d",&a,&b); g…