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. java.util.logging.Logger基础

    1. 定义 java.util.logging.Logger是Java自带的日志类,可以记录程序运行中所产生的日志.通过查看所产生的日志文件,可以分析程序的运行状况,出现异常时,分析及定位异常. 2. ...

  2. Java I/O基础

    字节流和字符流的区别,字节流一次读取一个字节,字符流一次读取的是一个Unicode码,读取了2个字节. 可以以文本编辑器打开的可以使用字符流读取,否则用字符流读取可能就会出错.图像文件就需要用字节流读 ...

  3. CF585E. Present for Vitalik the Philatelist [容斥原理 !]

    CF585E. Present for Vitalik the Philatelist 题意:\(n \le 5*10^5\) 数列 \(2 \le a_i \le 10^7\),对于每个数\(a\) ...

  4. BZOJ 2006: [NOI2010]超级钢琴 [ST表+堆 | 主席树]

    题意: 一个序列,求k个不相同的长度属于\([L,R]\)的区间使得和最大 前缀和,对于每个r找最小的a[l] 然后我yy了一个可持久化线段树做法...也许会T 实际上主席树就可以了,区间k小值 然后 ...

  5. CSS3及JS媒体查询教程

    CSS3媒体查询: 语法: <media_query_list>:<media_query>[,<media_query>] <media_query> ...

  6. Java的一些良好习惯及细节------持续更新中...

    1.在做条件判断时,不要将变量放在判断符的左边,这样做可以防止出现空指针异常,以字符串比较为例: String name = "Tom"; //这种方式不推荐,如果变量name为空 ...

  7. iOS "此证书由未知颁发机构签名"此问题的解决方法

    前段时间制作证书时把以前钥匙串中的证书全删除了,然后在制作新证书的时候就出现了"此证书由未知颁发机构签名"的红色警告,通过查找资料发现出现此问题的原因是:我把钥匙串中的此证书给删除 ...

  8. go get报错unrecognized import path “golang.org/x/net/context”…

    今天安装gin框架,首先下载gin,命令如下:go get github.com/mattn/go-sqlite3 结果报错: package golang.org/x/net/context: un ...

  9. 解决windows10和ubuntu16.04双系统下时间不对的问题

    电脑安装完windows10与ubuntu16.04双系统后,Ubuntu的时间总会和Windows的时间相差8小时,原因在于windows认为BIOS时间是本地时间,Ubuntu认为BIOS时间是U ...

  10. 拥抱.NET Core系列:MemoryCache 缓存过期

    在上一篇"拥抱.NET Core系列:MemoryCache 初识"中我们基本了解了缓存的添加.删除.获取,那么今天我们来看看缓存的过期机制.这里和上篇一样将把"Micr ...