CF1076B Divisor Subtraction 题解】的更多相关文章

Content 给定一个数 \(n\),执行如下操作: 如果 \(n=0\) 结束操作. 找到 \(n\) 的最小质因子 \(d\). \(n\leftarrow n-d\) 并跳到操作 \(1\). 请求出循环操作的次数. 数据范围:\(2\leqslant n\leqslant 10^{10}\). Solution 首先我们看是否是素数,如果是素数的话,那么其最小质因子一定是它本身,那么答案就是 \(1\). 如果不是素数,我们再根据奇偶性来分类讨论.由于偶数的情况比较简单,我们先讨论 \…
Description You are given an integer number nn. The following algorithm is applied to it: if n=0, then end algorithm; find the smallest prime divisor d of n; subtract dd from n and go to step 1. Determine the number of subtrations the algorithm will…
链接 [http://codeforces.com/contest/1076/problem/B] 题意 给你一个小于1e10的n,进行下面的运算,n==0 结束,否则n-最小质因子,问你进行多少步 分析 显然n为偶数时,,就会一直-2,不是偶数的话可能是合数或者素数 只需要找根号n内就可以找到合数的最小质因子,否则就是质数 一个奇数-一个奇数一定是偶数,看代码吧 代码 #include<bits/stdc++.h> using namespace std; #define ll long l…
题目链接:https://vjudge.net/problem/CodeForces-1076B 题意: 题目要求给定一个数,要求每次减去其最小素因数(既是素数又是其因数),问直到n=0需要做几次运算. 分析: 首先如果n为素数,则其最小素因数就是它本身,故第一次运算n:=n-n即得0,只需要一次运算.当n为偶数时,素因子恒为2,故每次减2直到0,所以运算次数为n/2次,当n为奇数是,首先减一次最小素因子,因为最小素因子一定是奇数,故奇-奇=偶,变为偶数后就按上述做法求得运算次数即可. 总结如下…
题目链接:https://codeforc.es/contest/1076 A. Minimizing the String 题意:给出一个字符串,最多删掉一个字母,输出操作后字典序最小的字符串. 题解:若存在一个位置 i 满足 a[i] > a[i+1],若不删除 a[i] 则后续操作不可能更优. #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long lo…
A. Minimizing the String time limit per test 1 second memory limit per test 256 megabytes Description: You are given a string ss consisting of nn lowercase Latin letters. You have to remove at most one (i.e. zero or one) character of this string in s…
ProblemA Minimizing the String 题目链接 题解:这一题读完题就写了吧.就是让你删除一个字母,使得剩下的字符组成的字符串的字典序最小:我们只要第一个当前位置的字符比下一个字符小的位置把该字符删去即可: 参考代码: #include<bits/stdc++.h> using namespace std; #define PI acos(-1.0) #define RI register int #define clr(a,b) memset(a,b,sizeof a)…
A - Minimizing the String solved 题意:给出一个字符串,可以移掉最多一个字符,在所有可能性中选取一个字典序最小的. 思路:显然,一定可以移掉一个字符,如果移掉的字符的后一个字符大于当前字符,那么字典序会变大. 那只需要从左往右,遇到第一个后面的字符大于当前字符的就可以移掉该字符. #include <bits/stdc++.h> using namespace std; #define N 200010 int n; char s[N]; int main()…
1076A 1076B 1076C 1076D 1076D A. Minimizing the String  You are given a string s consisting of n lowercase Latin letters.You have to remove at most one (i.e. zero or one) character of this string in such a way that the string you obtain will be lexic…
A. Minimizing the String 很明显,贪心之比较从前往后第一个不一样的字符,所以可以从前往后考虑每一位,如果把它删除,他这一位就变成\(str[i + 1]\),所以只要\(str[i] > str[i + 1]\),删除后一定是最优的. #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int N = 200010; int…
emmm...不能说是水题吧...小金羊以为考的是STL(手动滑稽)... 行,这个题说让分解因数(不一定非得质因数). 我们考虑到有第k个数有可能有\(x\cdot x=n\)的毒瘤情况, 并且题目明确要求说从小到大 --set帮助你轻松水过去. emmm....题目范围说是 \[1\leq n\leq 10^{15},1\leq k\leq 10^9\] 很明显朴素算法炸了! 我们需要知道\(x\cdot y=n\)的时候\(x\leq\sqrt{n}\),两侧同时平方,得到\(x^2\le…
#include <iostream> #include <cstdio> #include <string.h> #include <algorithm> using namespace std; /* 水题,注意字符范围是整个ASCII编码即可. */ ; int vis[maxn]; +]; +]; int main() { gets(s1); //getchar(); gets(s2); int len1=strlen(s1); int len2=s…
题意:给你n组,每组两个数字,要你给出一个数,要求这个是每一组其中一个数的因数(非1),给出任意满足的一个数,不存在则输出-1. 思路1:刚开始乱七八糟暴力了一下果断超时,然后想到了把每组两个数相乘,然后求每组的GCD,那么这个GCD就是因数的乘积(如果GCD==1就输出-1).然后打个2e5的素筛表,然后找到GCD的一个素数因数.做到这里好像没问题了,然而,分分钟会被hack,问题出在哪里了?显然啊,打素数表只用2e5的范围,但是因数还包括自己本身啊!所以一旦GCD大于2e5我们就找不到答案了…
Content 有两个数 \(a,b\),执行如下操作: 如果 \(a,b\) 中有一个数是 \(0\),结束操作,否则跳到操作 \(2\). 如果 \(a\geqslant 2b\),那么 \(a\leftarrow a-2b\),并跳回操作 \(1\),否则跳到操作 \(3\). 如果 \(b\geqslant 2a\),那么 \(b\leftarrow b-2a\),并跳回操作 \(1\),否则结束操作. 求出操作结束后的 \(a,b\). 数据范围:\(1\leqslant a,b\le…
Content 定义 \(n\) 个数对 \((a_1,b_1),(a_2,b_2),(a_3,b_3),...,(a_n,b_n)\) 的 \(\text{WCD}\) 为能够整除每个数对中至少一个数的 \(>1\) 的整数.现在,给出 \(n\) 个数对,请找出它们的 \(\text{WCD}\),或者这 \(n\) 个数对没有符合要求的 \(\text{WCD}\). 数据范围:\(1\leqslant n\leqslant 1.5\times 10^5,2\leqslant a_i,b_…
博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-Solution/ ———————————————————————————————————————— ———————————————————————————————————————— LeetCode OJ 题解 LeetCode OJ is a platform for preparing tech…
今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has a big rectangular cho…
[CF932E]Perpetual Subtraction(NTT,线性代数) 题面 洛谷 CF 题解 设\(f_{i,j}\)表示\(i\)轮之后这个数恰好为\(j\)的概率. 得到转移:\(\displaystyle f_{i,j}=\sum_{k=j}^{n}f_{i-1,k}*\frac{1}{k+1}\). 看成生成函数就有\(\displaystyle F_i(x)=\sum_{j=0}^{n}x^j\sum_{k\ge j}\frac{f_{i-1,k}}{k+1}\). 把两维换…
准备每天刷两题PAT真题.(一句话题解) 1001 A+B Format  模拟输出,注意格式 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; string ans = ""; int main() { ; cin >> a >> b; c = a + b; ) {…
BC都被hack的人生,痛苦. 下面是题解的表演时间: A. QAQ "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of leng…
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给出链接的所以不准偷偷复制博主的博客噢~~ 时隔两年,又开始刷题啦,这篇用于PAT甲级题解,会随着不断刷题持续更新中,至于更新速度呢,嘿嘿,无法估计,不知道什么时候刷完这100多道题. 带*的是我认为比较不错的题目,其它的难点也顶多是细节处理的问题~ 做着做着,发现有些题目真的是太水了,都不想写题解了…
刷题备忘录,for bug-free 招行面试题--求无序数组最长连续序列的长度,这里连续指的是值连续--间隔为1,并不是数值的位置连续 问题: 给出一个未排序的整数数组,找出最长的连续元素序列的长度. 如: 给出[100, 4, 200, 1, 3, 2], 最长的连续元素序列是[1, 2, 3, 4].返回它的长度:4. 你的算法必须有O(n)的时间复杂度 . 解法: 初始思路 要找连续的元素,第一反应一般是先把数组排序.但悲剧的是题目中明确要求了O(n)的时间复杂度,要做一次排序,是不能达…
突然很想刷刷题,LeetCode是一个不错的选择,忽略了输入输出,更好的突出了算法,省去了不少时间. dalao们发现了任何错误,或是代码无法通过,或是有更好的解法,或是有任何疑问和建议的话,可以在对应的随笔下面评论区留言,我会及时处理,在此谢过了. 过程或许会很漫长,也很痛苦,慢慢来吧. 编号 题名 过题率 难度 1 Two Sum 0.376 Easy 2 Add Two Numbers 0.285 Medium 3 Longest Substring Without Repeating C…
POI2010题解 我也不知道我为什么就开始刷POI了 有些题目咕掉了所以不完整(我都不知道POI到底有多少题) [BZOJ2079][Poi2010]Guilds (貌似bz跟洛谷上的不是一个题?) 并查集判孤立点就行了. #include<cstdio> #include<algorithm> using namespace std; int gi(){ int x=0,w=1;char ch=getchar(); while ((ch<'0'||ch>'9')&a…
反演套 DP 的好题(不用反演貌似也能做 Description Vivek initially has an empty array \(a\) and some integer constant \(m\). He performs the following algorithm: Select a random integer \(x\) uniformly in range from \(1\) to \(m\) and append it to the end of \(a\). Co…
Greatest Greatest Common Divisor Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5207 Description 在数组a中找出两个数ai,aj(i≠j),使得两者的最大公约数取到最大值. Input 多组测试数据.第一行一个数字T,表示数据组数.对于每组数据,第一行是一个数n,表示数组中元素个数,接下来一行有n个数,a1到an.1≤T≤…
B. Ehab and subtraction 题目链接:https://codeforc.es/contest/1088/problem/B 题意: 给出n个数,给出k次操作,然后每次操作把所有数减去最小值,输出这个最小值,k用不完用0来补. 题解: 考虑到重复的数会被一起减去,所以我用了个set来存放这n个数,然后用个累加器记录下减去了多少最小值,把数取出来时减去这个累加器就好了,最后用0来补. 代码如下: #include <bits/stdc++.h> using namespace…
Problem statement: Given a string representing an expression of fraction addition and subtraction, you need to return the calculation result in string format. The final result should be irreducible fraction. If your final result is an integer, say 2,…
E. Connected Components? time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an undirected graph consisting of n vertices and  edges. Instead of giving you the edges that exist i…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist. Divisor of n is any such natural number, t…