void extendgcd(long long a,long long b,long long &d,long long &x,long long &y) { ){d=a;x=;y=;return;} extendgcd(b,a%b,d,y,x); y -= x*(a/b); } //求解A+C*x=B(mod D),返回最小非负整数x long long ModX(long long A,long long B,long long C,long long D) { if(A==…
先上干货: 定理1: 如果d = gcd(a,b),则必能找到正的或负的整数k和l,使ax + by = d. (参考exgcd:http://www.cnblogs.com/dilthey/p/6804137.html) 定理2: 一元线性同余方程ax ≡ n (mod b) 有解,当且仅当gcd(a,b)|n. 也就是说,解出了ax+by=gcd(a,b),就相当于解出了ax≡n(mod b) (而且只要满足gcd(a,b)|n,就一定有解) 定理3: 若gcd(a,b) = 1,则方程ax…
题目链接: http://acm.hdu.edu.cn/showproblem.php? pid=1573 题目大意: 求在小于等于N的正整数中有多少个X满足:X mod a[0] = b[0], X mod a[1] = b[1], X mod a[2] = b[2], -, X mod a[i] = b[i], - (0 < a[i] <= 10). 思路: 先求出数组b[]中全部数的最小公倍数lcm,再求解出该一元线性同余方程组在lcm范围内的解为a.题目要 求解x是小于等于N的正整数,…
Hello Kiki Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 258 Accepted Submission(s): 111 Problem Description One day I was shopping in the supermarket. There was a cashier counting coins serio…
X问题 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5974 Accepted Submission(s): 2053 Problem Description 求在小于等于N的正整数中有多少个X满足:X mod a[0] = b[0], X mod a[1] = b[1], X mod a[2] = b[2], …, X mod…
套模板,因为要是正整数,所以处理一下x=0的情况. X问题 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4444 Accepted Submission(s): 1439 Problem Description 求在小于等于N的正整数中有多少个X满足:X mod a[0] = b[0], X mod a[1] = b[1], X…
一个exgcd解决一个线性同余问题,多个exgcd解决线性同余方程组. Strange Way to Express Integers Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 12001 Accepted: 3797 Description Elina is reading a book written by Rujia Liu, which introduces a strange way to expre…