随笔分类 -  算法-数论

摘要:求关于 x 的同余方程 ax ≡ 1 (mod b) 的最小正整数解。 输入描述 输入只有一行,包含两个正整数 a,b,用一个空格隔开。 对于40%的数据,2<=b<=1,000; 对于60%的数据,2<=b<=50,000,000; 对于100%的数据,2<=a,b<=2,000,000,000。 阅读全文
posted @ 2024-12-04 09:36 lipu123
摘要:链接:https://ac.nowcoder.com/acm/contest/73202/B 来源:牛客网 问题描述 有三种数量无限的砝码和一个天平,天平的一端有一个质量为\(m\)的物品,问能否通过放置砝码使得天平平衡? 输入描述: 第一行包含一个整数 \(T \ (1 \leq T \leq 1 阅读全文
posted @ 2024-01-17 16:33 lipu123
摘要:// 求x, y,使得ax + by = gcd(a, b) int exgcd(int a, int b, int &x, int &y) { if (!b) { x = 1; y = 0; return a; } int d = exgcd(b, a % b, y, x); y -= (a/b) 阅读全文
posted @ 2023-12-22 21:09 lipu123
摘要:https://leetcode.cn/problems/count-subarrays-where-max-element-appears-at-least-k-times/description/ 给你一个整数数组 nums 和一个 正整数 k 。 请你统计有多少满足「nums 中的最大元素」至 阅读全文
posted @ 2023-12-13 17:38 lipu123
摘要:这个需要素数筛 #include<iostream> #include<algorithm> using namespace std; const int maxn=4e5+100; int prime[maxn]; int biaoji[maxn]; int cnt; void getPrime( 阅读全文
posted @ 2023-10-22 10:36 lipu123
摘要:链接:https://ac.nowcoder.com/acm/contest/11216/G来源:牛客网 痛定思痛,奋楫争先再出发…… q 次询问。每次询问给定 n 和 K,问 1 ~ n 中有多少数可以表示为大于等于 K 的质数的乘积(一个数可以乘多次)。 输入描述: 链接:https://ac. 阅读全文
posted @ 2021-11-14 23:38 lipu123 阅读(91) 评论(0) 推荐(0)
摘要:题目链接 链接:https://ac.nowcoder.com/acm/contest/11216/G来源:牛客网 痛定思痛,奋楫争先再出发…… q 次询问。每次询问给定 n 和 K,问 1 ~ n 中有多少数可以表示为大于等于 K 的质数的乘积(一个数可以乘多次) 题解 可以发现,如果一个数的最小 阅读全文
posted @ 2021-11-11 23:57 lipu123 阅读(96) 评论(0) 推荐(0)
摘要:传送门 小y有$n$个数字$(1-n)$,他每次会在里面等概率随机选取两个数$x$,$y$(两个数互不影响),求$x%y==k$的概率(对23333取模) 保证$n%23333!=0$对$23333$取模的结果:假设答案化为最简分式后的形式为$a/b$, 其中$a$和$b$互质。 输出整数 x 使得 阅读全文
posted @ 2021-11-09 21:13 lipu123 阅读(76) 评论(0) 推荐(0)
摘要:题目描述 传送门 今天小A带同学们玩游戏,需要分为两组。每名同学为红队或蓝队。 为了方便分配颜色,小A让同学们站成n排m列。初始时,所有人都为红队成员。 小A可以进行p次操作1和q次操作2,操作解释如下: 操作1:把某一行的同学进行取反操作:即红队变为蓝队,蓝队变成红队。 操作2:把某一列的同学进行 阅读全文
posted @ 2021-10-27 19:43 lipu123 阅读(244) 评论(0) 推荐(0)
摘要:A group of contest writers have written nn problems and want to use kk of them in an upcoming contest. Each problem has a difficulty level. A contest 阅读全文
posted @ 2021-10-06 20:50 lipu123 阅读(52) 评论(0) 推荐(0)
摘要:The Euler function, φ, is known to be important in math theory. Given a positive integer n, φ(n) is defined as the number of integers in [1,n] that ar 阅读全文
posted @ 2021-09-28 00:59 lipu123 阅读(50) 评论(0) 推荐(0)
摘要:题目描述: 传送门 如果不知道三分的可以看看这个传送门 令$g(x)$为$x$中各位数和,例如$g(123456)=1+2+3+4+5+6$,然后有T次询问,每次询问给你一个$a$,$b$,$c$,$d$,$n$ 让你求$f(x)=Ax^{2}g(x)+Bx^{2}+Cxg^{2}(x)+Dxg(x 阅读全文
posted @ 2021-08-29 19:31 lipu123 阅读(47) 评论(0) 推荐(0)
摘要:组合数C(a, b) (预处理) typedef long long ll; const ll MOD = 1e9 + 7; // 必须为质数才管用 const ll MAXN = 1e5 + 3; ll fac[MAXN]; // 阶乘 ll inv[MAXN]; // 阶乘的逆元 ll QPow 阅读全文
posted @ 2021-08-28 20:46 lipu123 阅读(44) 评论(0) 推荐(0)
摘要:题目 题目链接 You are given an array aa of length nn. You are asked to process qq queries of the following format: given integers i and x, multiply ai by x. 阅读全文
posted @ 2021-08-04 21:34 lipu123 阅读(71) 评论(0) 推荐(0)
摘要:题目 题目描述 在一次运会上,有一个比赛项目,共有N个人参加比赛,要将这N个人分组,每组人数不少于K个,问有多少种分组方式?比如有16个运动员,每组人数不少于5个,共有6种分组方式:(1) 分一组,为16人;(2) 分二组,分别为11人、5人;(3) 分二组,分别为10人、6人;(4) 分二组,分别 阅读全文
posted @ 2021-07-27 10:37 lipu123 阅读(138) 评论(0) 推荐(0)
摘要:Among the strings of length A+B containing A occurrences of a and B occurrences of b, find the string that comes K-th in the lexicographical order.Con 阅读全文
posted @ 2021-07-24 12:17 lipu123 阅读(158) 评论(0) 推荐(0)
摘要:在遥远的公元前65536世纪,β星座的焃碁星人发现了地球,他们对于该星球上碳基生物的大脑构造感到非常的好奇, 在植入了夸克级别的神经元控制器后, 他们夺取了所有生物大脑内惊人的算力,进而控制了所有的生物。几亿年以后, 人类凭借着自己贫瘠的算力, 造出了庞大而惊人的超大规模集成电路,他们训练的Alph 阅读全文
posted @ 2021-07-22 11:34 lipu123 阅读(209) 评论(0) 推荐(0)
摘要:1862. 向下取整数对和 给你一个整数数组 nums ,请你返回所有下标对 0 <= i, j < nums.length 的 floor(nums[i] / nums[j]) 结果之和。由于答案可能会很大,请你返回答案对109 + 7 取余 的结果。 函数 floor() 返回输入数字的整数部分 阅读全文
posted @ 2021-06-19 18:23 lipu123 阅读(225) 评论(0) 推荐(0)
摘要:题目链接 给你一个二进制串 s (一个只包含 0 和 1 的字符串),我们可以将 s 分割成 3 个 非空 字符串 s1, s2, s3 (s1 + s2 + s3 = s)。 请你返回分割 s 的方案数,满足 s1,s2 和 s3 中字符 '1' 的数目相同。 由于答案可能很大,请将它对 10^9 阅读全文
posted @ 2021-06-18 00:10 lipu123 阅读(125) 评论(0) 推荐(0)