【链接】 我是链接,点我呀:)

【题意】

题意

【题解】

考虑怎么得到数字x2=N,假设是质数p的倍数
那么x1肯定在x2-p+1~x2这个范围内才行
因为p的倍数要刚好大于等于x1,
所以x1肯定是在这两个倍数之间才行
结果已经很显然了
肯定让p的值越大越好。
这样得到的x1才可能越小。
枚举x1在x2-p+1~x2之间。
用同样的方式得到x0就好。

【代码】

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5; int n;
int x0,x1,x2; int maxfac(int x){
int j = x;
for (int i = 2;i*i<=x;i++){
if (x%i==0){
while (x%i==0){
x/=i;
}
j = i;
}
}
if (x>1) j = x;
return j;
} int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> x2;
int p = x2-maxfac(x2)+1;
int ans = x2;
for (int x1 = p;x1 <= x2;x1++){
int temp = maxfac(x1);
if (temp!=x1){
x0 = x1-temp+1;
ans = min(ans,x0);
}
}
cout<<ans<<endl;
return 0;
}

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

  1. 【Codeforces 947A】 Primal Sport

    [题目链接] 点击打开链接 [算法] 不难看出,x1的范围是[x2-P(x2)+1,x2],x0的范围是[x1-P(x1)+1,x1] 我们可以先做一遍线性筛,然后暴力就可以了 [代码] #inclu ...

  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. Python基础 — OS

    OS模块 -- 简介   OS模块是Python标准库中的一个用于访问操作系统功能的模块,OS模块提供了一种可移植的方法使用操作系统的功能.使用OS模块中提供的接口,可以实现跨平台访问.但是在OS模块 ...

  2. c++ isdigit函数

    函数名:isdigit 函数所需头文件:#include<cstdio> 函数格式:isdigit(字符) 函数作用:判断括号内是否为1~9的数字. 例:isdigit(4) 就是true ...

  3. 实现grep命令

    #include <stdio.h> #include <string.h> #include <stdlib.h> // grep命令:grep match_pa ...

  4. List 的属性与方法整理

    List<T> 类与 ArrayList 类比较类似.它实现了 IList<T> 泛型接口,长度可以动态增加. 可以使用 Add 或 AddRange 方法将项添加到 List ...

  5. [转]ASP.NET MVC HtmlHelper扩展之Calendar日期时间选择

    本文转自:http://blog.bossma.cn/asp_net_mvc/asp-net-mvc-htmlhelper-calendar-datetime-select/ 这里我们扩展HtmlHe ...

  6. [ Luogu 3935 ] Calculating

    \(\\\) \(Description\) 若\(x\)分解质因数结果为\(x=p_1^{k_1}p_2^{k_2}\cdots p_n^{k_n}\),令\(f(x)=(k_1+1)(k_2+1) ...

  7. python中os模块中文帮助

    python中os模块中文帮助   python中os模块中文帮助文档文章分类:Python编程 python中os模块中文帮助文档 翻译者:butalnd 翻译于2010.1.7——2010.1.8 ...

  8. 引入css的四种方式

    1.内联式引用:直接用在标签上,但维护成本高 style='font-size:16px;color:#000000' 2.外部连接式引用:css代码与html代码分离,便于代码重复使用 <li ...

  9. 仿ofo单车做一个轮播效果

    github地址 首先我是利用swiper.js做的,因为这个很强大,哈哈~~,上代码 html很简单 <body> <div class="swiper-containe ...

  10. RabbitMQ - Publisher的消息确认机制

    queue和consumer之间的消息确认机制:通过设置ack.那么Publisher能不到知道他post的Message有没有到达queue,甚至更近一步,是否被某个Consumer处理呢?毕竟对于 ...