A. Primal Sport
time limit per test 1.5 seconds
memory limit per test 256 megabytes
input standard input
output standard output

Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try to reach one million by the process described below.

Alice goes first and then they take alternating turns. In the i-th turn, the player whose turn it is selects a prime number smaller than the current number, and announces the smallest multiple of this prime number that is not smaller than the current number.

Formally, he or she selects a prime p < Xi - 1 and then finds the minimum Xi ≥ Xi - 1 such that p divides Xi. Note that if the selected prime palready divides Xi - 1, then the number does not change.

Eve has witnessed the state of the game after two turns. Given X2, help her determine what is the smallest possible starting number X0. Note that the players don't necessarily play optimally. You should consider all possible game evolutions.

Input

The input contains a single integer X2 (4 ≤ X2 ≤ 106). It is guaranteed that the integer X2 is composite, that is, is not prime.

Output

Output a single integer — the minimum possible X0.

Examples
input

Copy

14

output
6

input

Copy

20

output
15

input

Copy

8192

output
8191

题意:初始有一个x0,你可以选择任意一个p满足p<x0且p是质数,之后计算x1为≥x0最小的p的倍数

然后再通过x1按照一样的算法得出一个x2

现给你一个x2,问x0最小可能是多少,保证有解(x2绝对不是质数)

稍加思考会发现,对于当前x2,x1的可能取值范围为[x2-p+1, x2],其中p为x2的最大质因子

暴力[x2-p+1, x2]中的每一个数作为x1,如果x1是质数就无视(因为这样就不可能存在x0),否则计算x0 = x1-p'+1

其中p'是x1的最大质因子,很显然最后答案就是min(x0)

#include<stdio.h>
#include<algorithm>
using namespace std;
int cnt, flag[1005] = {1,1}, pri[1005];
int Cha(int x)
{int i, bet;bet = 0;for(i=1;pri[i]*pri[i]<=x&&pri[i]!=0;i++){while(x%pri[i]==0){bet = max(bet, pri[i]);x /= pri[i];}}if(x!=1)bet = max(bet, x);return bet;
}
int main(void)
{int i, j, x2, now, ans;for(i=2;i<=1000;i++){if(flag[i])continue;pri[++cnt] = i;for(j=i*i;j<=1000;j+=i)flag[j] = 1;}scanf("%d", &x2);now = Cha(x2);ans = 10000000;for(i=x2-now+1;i<=x2;i++){now = Cha(i);if(now==i)continue;ans = min(ans, i-now+1);}printf("%d\n", ans);return 0;
}

VK Cup 2018 Round 1: A. Primal Sport相关推荐

  1. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)B. Primal Sport

    Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try ...

  2. Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3)

    点击打开A题链接 #include<bits/stdc++.h> using namespace std; const int MAX = 105; int n,s;int h[MAX], ...

  3. VK Cup 2018 Round 2: B. Three-level Laser(二分)

    C. Three-level Laser time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)切题报告(A-B题)

    这是我第二次参加CF比赛,也是第一次写博客,写得不好,望各位大佬海涵. A. Single Wildcard Pattern Matching 原题链接 这道题,这是难到让人无法直视,太水了. 题目大 ...

  5. Mail.Ru Cup 2018 Round 2

    Mail.Ru Cup 2018 Round 2 C. Lucky Days 题意:找出最长的一段连续区间,同时被\([l_a + k_at_a, r_a + k_at_a]\) , \([l_b + ...

  6. Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

    A. Doggo Recoloring ps:注意 n == 1 B. Weakened Common Divisor 题解:WCD出现中的数必然是 < a, b >中某个数的公约数.而 ...

  7. codeforces VK Cup 2018 - Wild-card Round 1 (unofficial unrated mirror)

    开开心心的打开codeforces, 本来打算疯狂AC一波,结果开了这一场,进去一看题好简单呀,火速交一发,结果交第二题的时候提示不让我交了??????????? 提示每种语言只能AC一道题,ok,难 ...

  8. CF#504,#505(based on VK Cup 2018 Final)上红记

    去年的我这时还是蓝名小哥,然后勉强上了紫. 当时写过一篇上紫记. 我 打cf频率在friends里还是偏高的,大概就是经常打出饱和状态. 1900- 徘徊过几场,2100±徘徊了好几个月,从noip2 ...

  9. VK Cup 2017 - Round 1

    传送门 A. Bear and Friendship Condition(思维or完全图判定) •题意 给你n个人,m个朋友关系 朋友是会传递的,若A B是朋友,A C是朋友,则必须有B C的朋友关系 ...

最新文章

  1. POI各Jar包的作用
  2. # 20155337 2017-2018-1 《信息安全系统设计基础》第二周课堂实践+myod
  3. python画羊_羊车门作业 Python版
  4. SharePoint Secure Store Service(SSSS)的使用(一)
  5. nginx使用用户真实IP做hash(解决经过CND后ip_hash失效问题)
  6. python求解比一个给定的数字大的最小对称数
  7. 基于等效积分形式的近似方法——加权余量法(配点法,伽辽金法)求解微分方程近似解
  8. 夜神模拟器连接手柄无反应_夜神模拟器怎么连接手柄?夜神模拟器连接手柄具体操作...
  9. 草图大师SketchUp2018下载和安装教程
  10. How to choose the number oftopics/partitions in a Kafka cluster?
  11. PAT日志 1031
  12. 苹果账号申请流程——99刀(个人版或公司版 ),299刀(企业版)
  13. 别总用git merge了,Git高级操作之选择合并,git将一个分支的提交合并到另一个分支,git cherry-pick
  14. 互联网日报 | 6月28日 星期一 | B站成立哔哩哔哩快乐奖学金;百度成立独立芯片公司昆仑芯;FF将于7月21日纳斯达克上市...
  15. 数据传输速率度量单位指标-比特、波特率和码元的关系
  16. android 监测属性值变化,Android 的系统属性(SystemProperties)分析 | Bob's Blo...
  17. 今天烧了3个菜之一,炖豆腐
  18. 安徽省2019年程序设计大赛 L.曲奇工厂 H.不要回文 K.福报
  19. 「自控元件及线路」5 步进电机及其控制
  20. 网页设计分割线代码_网页设计中的黄金分割

热门文章

  1. python软件如何下载-python软件怎么样?实际的操作方法来了
  2. python能做什么程序-python都能做什么
  3. python入门代码-python基础知识和练习代码
  4. python100例详解-Python类和实例详解
  5. SpringCloud--Eureka 注册中心原理及其搭建
  6. cs有的服务器弹道被修改了怎么办,【Counter-Strike】 服务器弹道设置。。。
  7. VUE图片预览放大缩小插件viewer
  8. vue中使用flexible.js并配合px2rem-loader实现移动端布局
  9. 4符号代码_ELF文件格式解析器 原理 + 代码
  10. html5圆形提交按钮样式,HTML5 SVG带圆形进度条动画的提交按钮特效