上一页 1 ··· 3 4 5 6 7 8 9 10 下一页
摘要: 裴蜀定理:对于一对正整数a, b, 存在非零整数x, y使得ax + by = gcd(a, b); ax + by 一定是最大公约数gcd(x, y)的倍数。 1) 如果b = 0,gcd(a, 0) = a, a就是最大公约数ax + by = a. (x = 1, y = 0是一组解) 0和x 阅读全文
posted @ 2020-04-18 15:15 龙雪可可 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 求a^k % p,(1 <= a, k, p <=10^9) #include <iostream> #include <algorithm> using namespace std; typedef long long LL; LL qmi(int a, int b, int p) { LL re 阅读全文
posted @ 2020-04-18 12:43 龙雪可可 阅读(488) 评论(0) 推荐(0) 编辑
摘要: 欧拉函数:φ(n)即在1~n中与n互质的数的个数φ(1) = 1, φ(2) = 1, φ(3) = 2,φ(4) = 2,φ(5) = 4,φ(6) = 2(即1、5) 对于一个数N肯定等于它的质因子的指数和:N = p1^φ1 + p2^φ2 + ……+pk^φk。 那么求该数的欧拉函数等于:φ 阅读全文
posted @ 2020-04-17 23:16 龙雪可可 阅读(2259) 评论(0) 推荐(0) 编辑
摘要: 试除法求约数: #include <iostream> #include <algorithm> #include <vector> using namespace std; int n; vector<int> get_divisors(int x) { vector<int> res; for( 阅读全文
posted @ 2020-04-17 19:57 龙雪可可 阅读(248) 评论(0) 推荐(0) 编辑
摘要: 埃氏筛法: #include <iostream> using namespace std; const int N = 1e6; int n, cnt, primes[N]; bool st[N]; void get_primes(int n) { //时间复杂度:n/2 + n / 3 + .. 阅读全文
posted @ 2020-04-17 17:22 龙雪可可 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 二分图的最大匹配: #include <iostream> #include <algorithm> #include <cstring> using namespace std; const int N = 510, M = 100010; int n1, n2, m; int h[N], e[M 阅读全文
posted @ 2020-04-16 20:48 龙雪可可 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 二分图染色法 即可以把所有的点划分到两个集合内,集合内部没有边存在。 一个图是二分图,当且仅当该图中不含奇数环 ——>不含奇数环,那么一定是二分图。有奇数环的话,那么就不能二分图。 判定二分图的依据:若出现一条边的两个端点是同样的颜色(即一个集合的话),那么就不能划分为二分图。 一条边的两个端点一定 阅读全文
posted @ 2020-04-16 20:08 龙雪可可 阅读(180) 评论(0) 推荐(0) 编辑
摘要: kruskal求最小生成树: #include <iostream> #include <algorithm> using namespace std; const int N = 100010; int p[N]; struct Edge{ int a, b, w; bool operator < 阅读全文
posted @ 2020-04-16 19:05 龙雪可可 阅读(141) 评论(0) 推荐(0) 编辑
摘要: prim算法求最小生成树 #include <iostream> #include <cstring> #include <algorithm> #include <queue> using namespace std; const int N = 501, INF = 0x3f3f3f3f; in 阅读全文
posted @ 2020-04-16 17:16 龙雪可可 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 854. Floyd求最短路 给定一个n个点m条边的有向图,图中可能存在重边和自环,边权可能为负数。 再给定k个询问,每个询问包含两个整数x和y,表示查询从点x到点y的最短距离,如果路径不存在,则输出“impossible”。 数据保证图中不存在负权回路。 输入格式 第一行包含三个整数n,m,k 接 阅读全文
posted @ 2020-04-16 16:22 龙雪可可 阅读(194) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 下一页
****************************************** 页脚Html代码 ******************************************