【题目链接】

点击打开链接

【算法】

不难看出,x1的范围是[x2-P(x2)+1,x2],x0的范围是[x1-P(x1)+1,x1]

我们可以先做一遍线性筛,然后暴力就可以了

【代码】

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6; int i,j,k,tmp,x,l,ans;
bool mark[MAXN+];
vector<int> Prime; template <typename T> inline void read(T &x) {
int f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
}
template <typename T> inline void writeln(T x) {
write(x);
puts("");
} int main() { read(x);
for (i = ; i <= MAXN; i++) {
if (!mark[i]) Prime.push_back(i);
for (k = ; k < Prime.size(); k++) {
tmp = i * Prime[k];
if (tmp > MAXN) break;
mark[tmp] = ;
if (i % Prime[k] == ) break;
}
}
for (i = ; i < Prime.size(); i++)
if (x % Prime[i] == ) l = x - Prime[i] + ;
ans = x;
for (i = ; i < Prime.size(); i++) {
for (j = * Prime[i]; j <= x; j += Prime[i]) {
if (j < l) continue;
ans = min(ans,j-Prime[i]+);
}
} writeln(ans); return ;
}

【Codeforces 947A】 Primal Sport的更多相关文章

  1. 【Codeforces 923A】Primal Sport

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 考虑怎么得到数字x2=N,假设是质数p的倍数 那么x1肯定在x2-p+1~x2这个范围内才行 因为p的倍数要刚好大于等于x1, 所以x1肯定是 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  4. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  5. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  6. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  7. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  8. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  9. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

随机推荐

  1. Oracle 12c在PDB中创建scott/tiger

    scott/tiger一直以来是oracle数据的默认用户,但是跟之前的版本相比,Oracle 12c引入了PDB管理,所以要麻烦一些 下面假设管理员为SYS/Oracle12csys,在orcl实例 ...

  2. 迁移桌面程序到MS Store(8)——通过APPX下载Win32Component

    在上一篇<迁移桌面程序到MS Store(7)——APPX + Service>中,我们提到将desktop application拆分成UI Client+Service两部分.其中UI ...

  3. Codeforces Gym 100286I iSharp 模拟

    原题地址:http://codeforces.com/gym/100286/attachments/download/2013/20082009-acmicpc-northeastern-europe ...

  4. noip2013华容道

    题目描述 [问题描述] 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面, 华容道是否根本就无法完成,如果能完成, 最少需要多少时间. 小 ...

  5. widows 2008 同步时间命令

    由于windows2008没有提供类似XP的自动同步功能,因此需要使用windows 2008计划任务来运行一行命令进行同步.   首先查看与想要同步时间的internet时间服务器的时差: w32t ...

  6. [Cypress] install, configure, and script Cypress for JavaScript web applications -- part3

    Use custom Cypress command for reusable assertions We’re duplicating quite a few commands between th ...

  7. Solidedge如何新建参考平面 参考面

    1 建立平行平面 点击平行平面 点击参考平面,输入相对距离   2 建立成角平面 先选择基准面,再选则旋转轴(第二次点击一个平面,该平面与基准面相交形成的直线即为旋转轴)   输入角度即可完成(鼠标左 ...

  8. 在 Edison 上自动启动 Arduino Sketch

    前言 原创文章,转载引用务必注明链接,水平有限,如有疏漏,欢迎指正. 本文使用Markdown写成,为获得更好的阅读体验和正常的链接.图片显示,请访问我的博客原文: http://www.cnblog ...

  9. iOS 身份证验证

    - (void)onClickButton:(id) sender{ || tmp_txt.text.length == ) { NSString *emailRegex = @"^[0-9 ...

  10. CSDN-markdown编辑器之从线上导入Markdown文件

      CSDN-markdown编辑器支持从线上导入Markdown文件的功能,假设你用其他支持Markdown的编辑器在网上写了博客文章或说明档,想公布到CSDN博客中,就能够使用本功能非常方便的完毕 ...