摘要: 一、性质求欧拉函数 from collections import Counter # 证明:容斥原理 # f(N) = N * (1 - 1/p1) * (1 - 1/p2) * ... * (1 - 1/pn) # 与N互质的数的个数: N - N/P1 - N/P2 - ... - N/Pn 阅读全文
posted @ 2024-04-03 18:17 gebeng 阅读(30) 评论(0) 推荐(0)
摘要: 一、中国剩余定理 from functools import reduce r = [2,3,2] # 要求mod里的数必须两两互质 mod = [3,5,7] def exgcd(a,b): if b == 0: return 1,0,a x,y,gcd = exgcd(b,a % b) x,y 阅读全文
posted @ 2024-04-03 11:45 gebeng 阅读(86) 评论(0) 推荐(0)
摘要: from math import sqrt from collections import Counter # ①试除法求约数 x = int(input()) ans = [] for i in range(1,int(sqrt(x)) + 1): if x % i == 0: ans.appen 阅读全文
posted @ 2024-04-02 22:07 gebeng 阅读(25) 评论(0) 推荐(0)
摘要: # 求 1 ~ n 所有的质数【线性筛,也叫欧拉筛,时间复杂度为O(n),埃氏筛为O(nlogn)】 n = int(input()) prime = [] vis = [0] * (n + 1) # 合数 = 最小质因子 × k (最大且不等于它自身的因数) # 每个合数必有一个【最小素因子】或【 阅读全文
posted @ 2024-04-02 21:18 gebeng 阅读(26) 评论(0) 推荐(0)
摘要: epsilon = pow(10,-10) g = [] for _ in range(int(input())): g.append([*map(float,input().split())]) n,m = len(g),len(g[0]) row = 0 for col in range(n): 阅读全文
posted @ 2024-04-02 20:01 gebeng 阅读(171) 评论(0) 推荐(0)
摘要: 灵茶之二分02 题目链接 https://codeforces.com/problemset/problem/1538/C 题目大意 输入 T(≤104) 表示 T 组数据。所有数据的 n 之和 ≤2e5。 每组数据输入 n(1≤n≤2e5) L R(1≤L≤R≤1e9) 和长为 n 的数组 a(1 阅读全文
posted @ 2024-04-01 22:27 gebeng 阅读(11) 评论(0) 推荐(0)
摘要: 一个动态维护前缀和的工具 class BIT: def __init__(self, n): self.tree = [0] * (n + 1) self.n = n def lowbit(self, x): return x & -x def update(self, x, k): while x 阅读全文
posted @ 2024-03-31 20:00 gebeng 阅读(23) 评论(0) 推荐(0)
摘要: 曼哈顿距离 两个单元格 \((x_i, y_i)\)和\((x_j, y_j)\) 之间的曼哈顿距离为 \(|x_i - x_j| + |y_i - y_j|\) 进一步总结,求最大的 \((x_i + y_i)_{max}\) - \((x_i + y_i)_{min}\) 与 最大的 \((x_ 阅读全文
posted @ 2024-03-31 16:30 gebeng 阅读(92) 评论(0) 推荐(0)
摘要: s = input() n = len(s) z = [0] * n left,right = 0,0 # z[i]表示s和s[i:]的LCP长度,规定z[0] = 0! for i in range(1,n): # 如果在z-box里,那么更新它的z[i]的值! if i <= right: z[ 阅读全文
posted @ 2024-03-31 10:27 gebeng 阅读(44) 评论(0) 推荐(0)
摘要: PMT:部分匹配表(Partial Match Table) 表示含义:t[0,i] 的前后缀最大匹配长度 s = input() t = input() n,m = len(s),len(t) pmt = [0] * m c = 0 for i in range(1,m): x = t[i] wh 阅读全文
posted @ 2024-03-30 17:00 gebeng 阅读(27) 评论(0) 推荐(0)