题意:有一个长度为n的数组a和一个长度为m的数组b,一个素数p.有n个集合,初始都只有一个1.现在,对(i从1到n)第i个集合执行以下操作: 对所有集合中的元素c,把c * (a[i] ^ b[j]) mod p 加入集合(j从1到m), 直到集合的元素不再增加为止. 问最后这n个集合的并有多少个元素? n到1e4, m到1e5, p到1e9. 思路(官方题解)这题运用了很多数论的知识,不对数论有一定了解比较难做出这道题. 涉及的知识:原根,阶,欧拉定理,贝祖定理. 首先我们知道,x ^ y m…
[CodeForces - 1225D]Power Products [数论] [分解质因数] 标签:题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory limit 524288 kB Source Technocup 2020 - Elimination Round 2 Tags hashing math number theory *1900 Site https://codeforces.com/problemset/problem/1225…
Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变一个数的值(注意不是真的改变),使得这个区间的gcd是小明所猜的数也算小明猜对.另一种操作就是真的修改某一点的值. 解题思路 这里我们使用线段树,维护区间内的gcd,判断的时候需要判断这个区间的左右子区间的gcd是不是小明猜的数的倍数或者就是小明猜的数,如果是,那么小明猜对了.否则就需要进入这个区间…
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Equation 题目大意:有一个数字n,让你给出任意两个合数a,b满足a - b = n. 我们知道大于2的偶数都是合数,那么如果n为奇数,只要n加上一个奇数合数一定也为合数,如果n为偶数,那么n加上一个偶数合数也一定为合数. 因为只求任意一组,就直接选择4,9,若为奇数输出 +n 和9,偶数输出 +…
题面 传送门:http://codeforces.com/problemset/problem/515/C Drazil is playing a math game with Varda. Let’s define f(x)f(x)for positive integer x as a product of factorials of its digits. For example, f(135)=1!∗3!∗5!f(135)=1!∗3!∗5! First, they choose a dec…
Codeforces 题目传送门 & 洛谷题目传送门 u1s1 感觉此题思维难度不太大,不过大概是细节多得到了精神污染的地步所以才放到 D1E 的罢((( 首先我们对所有 \(a_i,b_i\) 分解质因数并将它们全部质因子拎出来编个号 \(1,2,3,\cdots,m\)--这样的质因子个数肯定不会超过 \(2n\omega(a_i)\).我们记 \(ap_{i,j}\) 表示 \(a_i\) 中标号为 \(j\) 的质因子出现的次数,\(bp_{i,j}\) 表示 \(b_i\) 中标号为…
反演一下可以得到$b_i=\sum\limits_{d=1}^i{\mu(i)(\lfloor \frac{i}{d} \rfloor})^n$ 整除分块的话会T, 可以维护一个差分, 优化到$O(nlogn+klogk)$ #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map>…
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1951 分析: 练习数论知识的好题,涉及到费马小定理.lucas定理.求逆元…
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes. Note that you should find only the time after a minutes, see the examples t…
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is wr…
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/problem/A Description You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon…
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem/A Description Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x tha…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2114 自己对数论一窍不通啊现在,做了一道水题,贴出来吧...主要是让自己记住这个公式: 前n项和的立方公式为   : s(n)=(n*(n+1)/2)^2; 前n项和的平方公式为:s(n)=n*(n+1)(2*n+1)/6; 代码: #include<iostream> #include<cstdlib> #include<cstdio> using namespace s…
Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the le…
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received a young builder's kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other…
C. Tic-tac-toe 题目连接: http://www.codeforces.com/contest/3/problem/C Description Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3 × 3 grid (one player always draws…
Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election committee of Flatland is preparing for presidential elections. To minimize human factor in ballot counting they decided to develop an automated Ballot Ana…
Problem A. Arrangement of Contest 题目连接: http://codeforces.com/gym/100269/attachments Description Little Dmitry and little Petr want to arrange a contest. Their little friends submitted several task proposals and now Dmitry and Petr want to select som…
Levko and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Levko has an array that consists of integers: a1, a2, ... , an. But he doesn’t like this array at all. Levko thinks that the…
6月快要结束了 期末也过去大半了 马上就是大三狗了 取消了小学期后20周的学期真心长, 看着各种北方的学校都放假嗨皮了,我们这个在北回归线的学校,还在忍受酷暑. 过年的时候下定决心要拿块ACM的牌子,一直坚持刷题,这一个学期刷了200道吧,感觉还是小有收获.特别是Ural和Codeforces上的题,质量很高. 然后4月的校赛,5月的省赛,发挥的也一般,不过也没有太失常. 希望暑假的选拔赛能碰到有趣的队友 蛤蛤. 这两天各种考试,实在是太忙,看了一下edu24的题目,不是很容易,做了一道水题,以…
Codeforces 题面传送门 & 洛谷题面传送门 首先注意到这个图的特殊性:我们对于所有 \(s_i=s_j\)​ 的 \((i,j)\)​ 之间都连了条边,而字符集大小顶多只有 \(8\)​,因此当 \(n\)​ 比较大时这张图肯定是相当稠密的,故我们猜测这个直径长度肯定也不会太长.事实的确如此,具体来说,对于图上任意两个点 \(i,j\)​,它们之间最短距离的长度肯定不会超过 \(15\)​,具体证明大概就对于每一对字母 \((x,y)\)​,如果存在某两个位置 \(i,i+1\) 满足…
Codeforces 题目传送门 & 洛谷题目传送门 首先直接暴力枚举显然是不现实的,我们不妨换个角度来处理这个问题,考虑这 \(R_i\) 个瓶子中每一瓶被哪些熊在哪一天喝过. 我们考虑对这 \(R_i\) 个瓶子各建立一个 \(q\times n\) 的 01 矩阵,第 \(j\) 行第 \(k\) 列为 \(1\) 表示第 \(k\) 只熊在第 \(j\) 天尝过了这瓶酒,反之第 \(k\) 只熊在第 \(j\) 天尝过了这瓶酒. 那么题目中的条件可表示为: 每一个表格里 \(1\) 的个…
Codeforces 题目传送门 & 洛谷题目传送门 下设 \(n,m\) 同阶. 首先有一个傻子都会的暴力做法,枚举矩形的上.下边界 \(l,r\),考虑集合多重集 \(S=\{y|x\in[l,r],(x,y)\text{为标记点}\}\),也就是所有在第 \(l\) 行与第 \(r\) 行之间所有标记点的列坐标的集合,考虑进一步枚举矩形的左端点 \(x\),那么对于右端点 \(y\),以 \((l,x)\) 为左上角,\((r,y)\) 为右下角的矩形中至少有 \(k\) 个标记点当前仅当…
Codeforces 题目传送门 & 洛谷题目传送门 obviously,难度高一点的构造题对我来说都是不可做题 首先考虑将排列拆成一个个置换环,也就是 \(\forall i\) 连边 \(i\to p_i\),显然这样我们可以得到一个个环. 首先考虑怎样同时处理两个置换环,假设有两个环,长度分别为 \(p,q\),元素分别为 \(x_1,x_2,\cdots,x_p;y_1,y_2,\cdots,y_q\).我们考虑以下步骤同时将这两个环中所有元素复位: 交换 \(x_1,y_1\),两个置…
A 题 Vasily the Bear and Triangle 题目大意 一个等腰直角三角形 ABC,角 ACB 是直角,AC=BC,点 C 在原点,让确定 A 和 B 的坐标,使得三角形包含一个矩形,这个矩形一个角在原点,另一个点在 (x, y) 处,并且三角形 ABC 的面积尽量小 将 A B 两点按照 x 坐标从小到大输出 做法分析 A B 两点必然在坐标轴上,且线段 AB 经过点 (x, y),那么简单分类讨论下就行了 交之前犹豫了一下,10分钟才提交... 参考代码 #include…
题目链接: A. Memory and Crow time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows pe…
Description Kevin Sun wants to move his precious collection of n cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into k boxes of a fixed size. In order to keep his collectio…
Description After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the a…
Description  meter long road between his house and the first shop and a d2 meter long road between his house and the second shop. Also, there is a road of length d3 directly connecting these two shops to each other. Help Patrick calculate the minimum…
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102271#problem/B Description Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500,…