CodeForces-822D 【最小素因子应用】】的更多相关文章

题目大意:一场选美比赛有N个人,可以分成N/x,每组x人.每组的比较次数为x(x-1)/2,f[N]为最后决出冠军所需的比较次数,可以通过改变x的值使f[N]改变.题目给出t,l,r(1 ≤ t < 109 + 7, 2 ≤ l ≤ r ≤ 5·106).求 t^0⋅f(l)+t^1⋅f(l+1)+⋯+t^r−l⋅f(r) 的最小值对1e9+7的模. 解题思路:①如果人数为素数,那f[N]=N(N-1)/2; ②如果不是素数,那就找出最小素因子x,分成N/x,每组x人,f[N]=N/x*f[x]…
任意门:https://vjudge.net/problem/CodeForces-822D D. My pretty girl Noora time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output In Pavlopolis University where Noora studies it was decided to hold…
Problem Description A positive proper divisor is a positive divisor of a number n, excluding n itself. For example, 1, 2, and 3 are positive proper divisors of 6, but 6 itself is not.Peter has two positive integers n and d. He would like to know the…
In Pavlopolis University where Noora studies it was decided to hold beauty contest "Miss Pavlopolis University". Let's describe the process of choosing the most beautiful girl in the university in more detail. The contest is held in several stag…
大意: 两个n元素集合$A$, $B$, $A_i$与$A_{i+1}$连一条有向边, $B_i$与$B_{i+1}$连一条有向边, 给定$m$条从$A_i$连向$B_j$的有向边, 每次询问修改$A_x->A_{x+1}$的边权, 求$A_1$->$B_n$的最大流. 先转为最小割, B上的边不修改, 割B的最小值可以预处理出来. 若割A答案就为$min(a_i+sum_i)$…
Digital collectible card games have become very popular recently. So Vova decided to try one of these. Vova has n cards in his collection. Each of these cards is characterised by its power pi, magic number ci and level li. Vova wants to build a deck…
题意及思路:https://www.cnblogs.com/Yuzao/p/8494024.html 最小割树的实现参考了这篇博客:https://www.cnblogs.com/coder-Uranus/p/9771919.html 代码: #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; const int maxn = 210; const int maxm = 2010; int head[maxn…
题目传送门 sol:Pollard_Rho的模板题,刚看了Pollard_Rho和Miller_Rabin很多原理性的东西看不懂,只是记住了结论勉强能敲代码. Pollard_Rho #include "cstdio" #include "cstdlib" #include "algorithm" #include "ctime" using namespace std; typedef long long LL; LL gc…
题目链接: https://codeforces.com/contest/707/problem/C 题目: 题意: 告诉你直角三角形的一条边,要你输出另外两条边. 思路: 我们容易发现除2外的所有素数x作为直角边,那么另外两条边的长度一定为(x * x - 1)/2和(x * x + 1)/2,因此对于每个数我们只需要找到n的最小素因子(除2外)即可,需要额外处理一下2的幂次. 代码实现如下: #include <set> #include <map> #include <…
题目链接:http://codeforces.com/contest/402/problem/D 题意:给出一个a串和素数串b .f(1) = 0; p为s的最小素因子如果p不属于b , 否则 . a串还可以进行这样的操作找一个r使得(1<=r<=n)g=gcd(a[1],a[2]......a[r]),然后再是a[1~r]/g. 题解:其实f的求和可以理解为num1(好的素因子)-num2(不好的素因子). 然后就是对a操作的理解,a怎么样才需要进行这样的操作呢?只要g中不好的素因子大于好的…