CodeForces 300C --数论】的更多相关文章

A - A Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 300C Description Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the deci…
A Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 300C Description Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal…
题目链接: http://codeforces.com/contest/300/problem/C 本来是道不难的题目,还是自己的数学功底不扎实. 从该题又一次巩固了关于乘法逆的概念,在剩余系中,如果要做除法,如 a / b%n ,  此时应该计算 a * (b在n下的逆), 而不是直接计算 a / b 另外一点值得注意的是,如果 n 为一素数,那么 b 的逆就是 pow_mod(a, n-2, n). 模拟叫做费马小定理. 乘法逆真的很重要.务必牢记!!! 附AC代码: /**********…
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序列中所有值都能被其中一个值整除,②且子序列范围尽可能大(r-l尽可能大). 解题思路: 对于要求1,不难发现只有min(L,R)=gcd(L,R)时才行.其中gcd是L,R范围内的最大公约数,min是L,R范围内的最小值. 对于要求2,传统思路是r-l从大到小枚举,每次确定一个(L,R)范围,进行判…
题目链接:http://codeforces.com/problemset/problem/264/B 代码: #include<cstdio> #include<iostream> #include<vector> #include<cstring> using namespace std; ; int dp[maxn]; vector<int> dx[maxn]; void get_div() //筛因子 { ; i<maxn; i++…
题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum_{i = 1}^{n} a_{i} \leqslant K$的最大正整数$d$. 整理一下可以得到条件是$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil \leqslant K + \sum_{i = 1}^{n} a_{i}$…
C. Beautiful Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal…
题目 CodeForces 1213G 做法 假设有\(P\)个完整的循环块,假设此时答案为\(K\)(实际答案可能有多种),即每块完整块长度为\(K\),则\(P=\left \lfloor \frac{N}{K} \right \rfloor\) 假设循环快中有\(p_a,p_b\)个\(A\)和\(B\),则 \(p_a\cdot P\le a\Longrightarrow p_a\le \left \lfloor \frac{a}{P} \right \rfloor\) \(p_a\cd…
Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n. Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom…
Neko does MathsCodeForces - 1152C 题目大意:给两个正整数a,b,找到一个非负整数k使得,a+k和b+k的最小公倍数最小,如果有多个k使得最小公倍数最小的话,输出最小的k. 首先让b>a,由lcm(a,b)=a*b/gcd(a,b),可以得出如果b%a==0,那么它们的最小公倍数就是b,此时的k就等于0.但如果b%a!=0的话,我们设g=gcd(a+k,b+k),那么就是有a+k=q1*g,b+k=q2*g,两者做差,那么b-a=(q2-q1)*g,由此我们可以知…