qtmd的复习pat,老子不想看了,还不如练几道cf

这题首先可以很容易想到讨论最后的共因子为素数
这个素数太多了,1-1e6之间的素数
复杂度爆炸
所以使用了前缀和,对于每个素数k的每个小区间
(kg, k(g + 1)]是可以直接求这个区间的最佳方案的

#include<iostream>
#include<map>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e6+5;
#define MS(x,y) memset(x,y,sizeof(x))
#define MP(x, y) make_pair(x, y)
const int INF = 0x3f3f3f3f; ll sum[N];
int cnt[N];
int isprime[N]; int j;
ll Sum(int x) {
if(x <= j) return sum[j];
else if(x >= N) return sum[N-1];
else return sum[x];
}
int Cnt(int x) {
if(x <= j) return cnt[j];
else if(x >= N) return cnt[N-1];
else return cnt[x];
}
int main() {
int n, x, y;
while(~scanf("%d %d %d", &n, &x, &y)) {
int ed = x/y;
for(int i = 0; i < n; ++i) {
int a; scanf("%d", &a);
sum[a] += a;
cnt[a] ++;
}
for(int i = 1; i < N; ++i) {
sum[i] += sum[i-1];
cnt[i] += cnt[i-1];
}
ll ans = 1e18; for(int i = 2; i < N; ++i) {
if(!isprime[i]) {
ll tmp = 0;
for(j = 0; j < N; j += i) {
isprime[j] = 1; int fr1 = j + i - 1; int to1 = j + i - ed - 1; int fr2 = j + i - ed - 1; int to2 = j; ll t1 = Sum(fr1) - Sum(to1); int t2 = Cnt(fr1) - Cnt(to1);
int t3 = Cnt(fr2) - Cnt(to2);
// if(i == 17 && j < 20) printf("%d %lld %d %d %lld\n", j, t1, t2, t3, tmp); tmp += 1ll*(1ll*t2*(j+i) - t1) * y + 1ll* t3 * x;
}
ans = min(ans, tmp);
}
}
printf("%lld\n", ans);
}
return 0;
}

Codeforces Round #432 (Div. 1) B. Arpa and a list of numbers的更多相关文章

  1. Codeforces Codeforces Round #432 (Div. 2 D ) Arpa and a list of numbers

    D. Arpa and a list of numbers time limit per test   2 seconds memory limit per test     256 megabyte ...

  2. Codeforces Round #432 Div. 1 C. Arpa and a game with Mojtaba

    首先容易想到,每种素数是独立的,相互sg就行了 对于一种素数来说,按照的朴素的mex没法做... 所以题解的简化就是数位化 多个数同时含有的满参数因子由于在博弈中一同变化的,让他们等于相当于,那么这样 ...

  3. Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)ABCD

    A. Arpa and a research in Mexican wave time limit per test 1 second memory limit per test 256 megaby ...

  4. Codeforces Round #432 (Div. 2)

    A. Arpa and a research in Mexican wave Arpa is researching the Mexican wave. There are n spectators ...

  5. D. Arpa and a list of numbers Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)

    http://codeforces.com/contest/851/problem/D 分区间操作 #include <cstdio> #include <cstdlib> # ...

  6. 【前缀和】【枚举倍数】 Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) D. Arpa and a list of numbers

    题意:给你n个数,一次操作可以选一个数delete,代价为x:或者选一个数+1,代价y.你可以进行这两种操作任意次,让你在最小的代价下,使得所有数的GCD不为1(如果全删光也视作合法). 我们从1到m ...

  7. 【推导】Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) B. Arpa and an exam about geometry

    题意:给你平面上3个不同的点A,B,C,问你能否通过找到一个旋转中心,使得平面绕该点旋转任意角度后,A到原先B的位置,B到原先C的位置. 只要A,B,C构成等腰三角形,且B为上顶点.那么其外接圆圆心即 ...

  8. 【Codeforces Round #432 (Div. 2) A】 Arpa and a research in Mexican wave

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] t<=k,输出t t>=n,输出k-t+n 其他情况都是k [错的次数] 0 [反思] 在这了写反思 [代码] /* */ #in ...

  9. 【Codeforces Round #432 (Div. 2) B】Arpa and an exam about geometry

    [链接]h在这里写链接 [题意] 给你3个点A,B,C 问你能不能将纸绕着坐标轴上的一点旋转.使得A与B重合,B与C重合 [题解] 这3个点必须共圆. 则A,B,C不能为一条直线.否则无解. 共圆之后 ...

随机推荐

  1. 自动化测试selenium(四)check,选中复选框,操作一组元素

    定位复选框位置 打开浏览器,按F12,审查元素 接下来,我们要实现选中复选框 List<WebElement> inputs = driver.findElements(By.tagNam ...

  2. HDU1013,1163 ,2035九余数定理 快速幂取模

    1.HDU1013求一个positive integer的digital root,即不停的求数位和,直到数位和为一位数即为数根. 一开始,以为integer嘛,指整型就行吧= =(too young ...

  3. Scrapy框架实战-妹子图爬虫

    Scrapy这个成熟的爬虫框架,用起来之后发现并没有想象中的那么难.即便是在一些小型的项目上,用scrapy甚至比用requests.urllib.urllib2更方便,简单,效率也更高.废话不多说, ...

  4. 帝国CMS备份出现数据恢复不完整的问题

    今天linux主机中毒了,把用帝国备份王备份之后,恢复了快照到刚建主机的状态: 哎,只怪当初没有勤快的去做快照啊: 重新配置好后: 开始使用帝国备份王: 数据恢复之后,打开文章,提示"附加表 ...

  5. PHP 5.6 微信上传临时素材的坑

    /** * 上传素材 */ function add_material($url){ $access_token = wx_access_token(); $wx_url = "https: ...

  6. Math Jax开源数学编辑器的使用

    首先,这是一个开源免费,同时也可以支持扩展的软件. 使用API文档: 中文网站(http://mathjax-chinese-doc.readthedocs.io/en/latest/index.ht ...

  7. PHP读取大文本文件并处理数据的思路

    //处理文件 $file = fopen($filename, "r") or exit("Unable to open file!"); $total_lin ...

  8. docker 实践(一)

    docker 简介 容器虚拟化,比传统的虚拟化轻量 2013年出现,发展非常迅猛 Redhat在6.5版本开始支持docker 使用go语言开发,基于apache2.0协议 开源软件,项目代码在git ...

  9. eclipse 使 用Ctrl+鼠标左键进入mapper.xml文件的方法

    在 >eclipse MarketPlace中下载>Mybatipse 插件安装重启即可完成

  10. Tomcat8.5.24日志自动清理(maxDays)功能探究

    前言 测试人员反馈tomcat目录下的日志占用空间很大,需要自动清理.接到这个反馈时,想象着应该是一个很简单的功能,tomcat应该已经实现了日志的自动清理功能.于是乎,我先到网上查询了如何自动清除t ...