题意: 求\(x^2 \equiv a \mod p\) 的所有整数解 思路: 二次剩余定理求解. 参考: 二次剩余Cipolla's algorithm学习笔记 板子: //二次剩余,p是奇质数 ll ppow(ll a, ll b, ll mod){ ll ret = 1; a = a % mod; while(b){ if(b & 1) ret = ret * a % mod; a = a * a % mod; b >>= 1; } return ret; } struct TT…
http://acm.timus.ru/problem.aspx?space=1&num=1132 题意: 求 x^2 ≡ n mod p  p是质数 的 解 本题中n>=1 特判p=2,接下来求当p是奇素数时的解 引理1: 引理2:方程有解当且仅当 定理: 设a满足 不是模p的二次剩余, 即无解, 那么是二次剩余方程的解 #include<cstdio> #include<cstdlib> #include<algorithm> using namesp…
不理解,背板子 #include<cstdio> using namespace std; int Pow(int a,int b,int p) { ; ) ) res=1LL*a*res%p; return res; } bool Legendre(int a,int p) { >>,p)==; } void modsqr(int a,int p) { int x; int i,k,b; ) x=a%p; ==) x=Pow(a,p+>>,p); else { ;Le…
题意1.1: 求\(\sum_{i=1}^n Fib^m\mod 1e9+9\),\(n\in[1, 1e9], m\in[1, 1e4]\) 思路1.1 我们首先需要知道斐波那契数列的通项是:\(Fib_i = \frac{\sqrt5}{5}[(\frac{1+\sqrt5}{2})^i-(\frac{1-\sqrt5}{2})^i]\),因为取模是个质数,我们可以用二次剩余定理得到\(\sqrt5 \mod 1e9+9 = 383008016\),然后就可以得到\(\frac{\sqrt5…
A. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) an…
The problem is so easy, that the authors were lazy to write a statement for it! Input The input stream contains a set of integer numbers Ai (0 ≤ Ai ≤ 1018). The numbers are separated by any number of spaces and line breaks. A size of the input stream…
A. Plus and Square Root 题目连接: http://codeforces.com/contest/715/problem/A Description ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '' (square root). Initially, the number 2 is d…
题目传送门 /* 题意:问n最少能是几个数的平方和 01背包:j*j的土地买不买的问题 详细解释:http://www.cnblogs.com/vongang/archive/2011/10/07/2200721.html */ #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> using namespace std; ; const int INF = 0x…
The problem is so easy, that the authors were lazy to write a statement for it! Input The input stream contains a set of integer numbers Ai (0 ≤ Ai ≤ 10^18). The numbers are separated by any number of spaces and line breaks. A size of the input strea…
Square root digital expansion It is well known that if the square root of a natural number is not an integer, then it is irrational. The decimal expansion of such square roots is infinite without any repeating pattern at all. The square root of two i…