Codeforces 354C 暴力 数论
题意:给你一个数组,你可以把数组中的数减少最多k,问数组中的所有数的GCD最大是多少?
思路:容易发现,GCD的上限是数组中最小的那个数,而因为最多可以减少k,及可以凑出来的余数最大是k,那么GCD的下限是k + 1,所以当最小的数小于等于k + 1时,答案是最小的数。如果最小的数大于k + 1,我们从大到小枚举GCD,假设当前枚举的数是x,那么如果一个数在[t * x, t * x + k](t是一个常数)之间,那么就可以被凑出来,我们看一下最后凑出来的数是不是n个就可以了。我们可以用前缀和优化,这样查询区间操作是O(1)的。因为调和复杂度是nlogn的,所有可以过。
代码:
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define db double
#define pii pair<int, int>
using namespace std;
const int maxn = 300010;
int a[maxn];
int sum[1000010];
int main() {
int n, k, mi = 1e9;
// freopen("Cin.txt", "r", stdin);
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
mi = min(mi, a[i]);
}
if(mi <= k + 1) {
printf("%d\n", mi);
}
for (int i = 1; i <= n; i++) {
sum[a[i]]++;
}
for (int i = 1; i <= 1e6; i++)
sum[i] += sum[i - 1];
for (int i = mi; i >= k + 1; i--) {
int now = 0;
for (int j = 1; i * j <= 1e6; j++) {
now += sum[min(1000000, i * j + k)] - sum[i * j - 1];
if(now == n) {
printf("%d\n", i);
return 0;
}
}
}
}
Codeforces 354C 暴力 数论的更多相关文章
- Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)
Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...
- CodeForces 670D1 暴力或二分
今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1 This problem is given in two versions that diff ...
- codeforces 735D Taxes(数论)
Maximal GCD 题目链接:http://codeforces.com/problemset/problem/735/D ——每天在线,欢迎留言谈论. 题目大意: 给你一个n(2≤n≤2e9) ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...
- Codeforces Round #425 (Div. 2) Problem B Petya and Exam (Codeforces 832B) - 暴力
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...
- codeforces 691F 暴力
传送门:https://codeforces.com/contest/691/problem/F 题意:给你n个数和q次询问,每次询问问你有多少对ai,aj满足ai*aj>=q[i],注意 a* ...
- Vicious Keyboard CodeForces - 801A (暴力+模拟)
题目链接 题意: 给定一个字符串,最多更改一个字符,问最多可以有多少个“VK”子串? 思路: 由于数据量很小,不妨尝试暴力写.首先算出不更改任何字符的情况下有多个VK字串,然后尝试每一次更改一个位置的 ...
随机推荐
- zuul 详解
zuul的简单使用与分析: https://www.jb51.net/article/106716.htm https://www.jianshu.com/p/ff863d532767 zuul自定义 ...
- 分享学做的一个jsp注册页面
分享一个自己学习时,用bootstrap,多方搜索做的注册页面,包括页面的非空验证.导入相关的bootstrap的js和css文件就可以了.背景很丑,可以自己换一个.后面进一步完善<( ̄︶ ̄)↗ ...
- js 中HTML的 onkeycode 和onkeydown属性事件
<!DOCTYPE html><html><head><script>function displayResult(){var x=document.g ...
- Spring Transaction Isolation
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11530702.html Reference http://docs.spring.io/spring/ ...
- NET Core+win10+Jenkins+Gogs+open ssh持续集成
背景 阿里云测试环境一台,带宽1M跟不上,Jenkins安装一个插件耗时很长,于是想在本地搭建Jenkins服务,将生成的安装文件同步到目标服务器上. 技术点有: win10:本地环境是win10,测 ...
- u-tools图床便捷生成markdown图片
u-tools 图床 上传图片生成markdown图片非常便捷. 支持的图片服务器有几种,其中搜狗.网易和掘金的加载速度更快些: 也可以用阿里与和腾讯云的OSS; 其中网易生成图片不是原图尺寸好像被改 ...
- maven插件之maven-surefire-plugin,junit单元测试报告和sonar测试覆盖率的整合说明
POM中配置的如下: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId> ...
- JS 判断undefined
tax !== underfined underfined 是判断的是类型的结果, 如果加typeof后是字符串类型 写法:typeof(tax) !== "underfined" ...
- C++ 递推法 斐波那契数列 兔子产仔
#include "stdio.h" #include "iostream" int Fibonacci(int n) { int t1, t2; || n = ...
- sql200安装问题
解决方法: 首先把安装目录和C:\Program Files下的Microsoft SQL Server文件夹删了,删除在current_user和local_machine\software\mic ...