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. bzoj 4591: [Shoi2015]超能粒子炮·改 [lucas定理]

    4591: [Shoi2015]超能粒子炮·改 题意:多组询问,求 \[ S(n, k) = \sum_{i=0}^n \binom{n}{i} \mod 2333,\ k \le n \le 10^ ...

  2. BZOJ 2419: 电阻 [高斯消元 物理]

    http://www.lydsy.com/JudgeOnline/problem.php?id=2419 题意: n个点m个电阻构成一张图,求1到n的等效电阻 第一节课看一道题弃疗,于是来做这道物理题 ...

  3. javamail+ical4j发送会议提醒

    本篇讲述小编在使用ical4j时对其的理解与使用,留作笔记的同时希望能帮助到大家! 初学者可以先了解下ical4j的基本信息: iCalender编程基础,了解与使用ical4j:https://ww ...

  4. IDEA设置优化

    默认会开很多的功能,但是有些功能暂时用不到,于是想屏蔽掉. Duplicated Code冗余代码提示功能 先找到设置路径Settings -> Editor -> Inspections ...

  5. linux scp远程拷贝文件及文件夹

    [http://www.jb51.net/LINUXjishu/73131.html] 1.拷贝本机/home/administrator/test整个目录至远程主机192.168.1.100的/ro ...

  6. 借助Maven入手Spring Boot第一个程序

    目前网上有不少Spring Boot的入门文章,都很有帮助,本人最近在深入学习Spring Cloud,在搭建第一个Hello World程序时,感觉对于新手而言,介绍文章怎么详细都不为过,因为其中坑 ...

  7. js分页功能实现

    实现一个js的分页并在弹出框中显示 1.分页插件使用:bootstarp-paginator.js,需要先引入bootstarp.js和jquery.js等: !function($){"u ...

  8. 五分钟了解Hash算法

    Hash算法详解 想象一下如果高级语言(Java,C++ ,C#)中如果没有实现类似List.Map等数据结构,企业级应用开发将是多么痛苦的事吧? Key-Value这种数据结构对于数据处理非常方便. ...

  9. vuejs、eggjs全栈式开发设备管理系统

    vuejs.eggjs全栈式开发简单设备管理系统 业余时间用eggjs.vuejs开发了一个设备管理系统,通过mqtt协议上传设备数据至web端实时展现,包含设备参数分析.发送设备报警等模块.收获还是 ...

  10. 函数重载overload

    与void show(int a, char b, double c){}构成重载的有: a) void show(int x, char y, double z){} //no b) int sho ...