【Codeforces 923A】Primal Sport
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
考虑怎么得到数字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的更多相关文章
- 【Codeforces 947A】 Primal Sport
[题目链接] 点击打开链接 [算法] 不难看出,x1的范围是[x2-P(x2)+1,x2],x0的范围是[x1-P(x1)+1,x1] 我们可以先做一遍线性筛,然后暴力就可以了 [代码] #inclu ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
随机推荐
- springAOP配置XML方式配置切面报错error at ::0 formal unbound in pointcut
[错误配置文件] <aop:config> <aop:pointcut expression="execution(* net.fifteenho.service.impl ...
- ipvs和ipvsadm
ipvs和ipvsadm ipvs:内核中的协议栈上实现 ipvs是LVS软件核心,是运行在LB上的,这是个基于ip层的负载均衡. ipvs的总体结构主要有ip包处理,负载均衡算法,系统配置和管理三个 ...
- bzoj 4807: 車【组合数+高精+线性筛】
设n>m,答案是\( C_n^m \),然后高精就行了 具体做法是先把指数筛出来,然后对每个数因数分解,记录质因子个数,最后被除数减去除数质因子个数,把剩下的质因子乘起来就行了 #include ...
- bzoj Strange Way to Express Integers【excrt】
其实我没看懂题不如说根本没看--都说是excrt板子那就写个板子吧 注意开long long #include<iostream> #include<cstdio> using ...
- 全面学习ORACLE Scheduler特性(10)管理Chains
5.2 管理Chains 5.2.1 修改Chains属性 基本上碰到修改CHAIN属性的机率不会太大,因此确实没啥可修改的,对于CHAIN对象来说,能够修改的属性只有两个:evaluation_ ...
- [转]Windows Azure平台简介(一):定位与产品结构
本文转自:http://blog.csdn.net/azurechina/article/details/5592236 http://blogs.msdn.com/b/azchina/archive ...
- idea之映射servlet问题
方式一: 配置web.xml如下节点,事例如下: servlet> <servlet-name>HelloWorld</servlet-name> ...
- eclipse安装提示错误:Failed to load JNI shared library "D:\jdk1.7\client\jvm.dll"
错误截图如下 原因是jdk32位,eclipse64位导致,修改jdk版本为64位或者修改ecipse版本为32位即可.
- Python,计算 ax^2 + bx + c = 0的根
1 #-*-coding : utf-8-*- 2 import math 3 4 def quadratic(a, b, c): 5 if not isinstance(a, (int, float ...
- 对于es6的小小理解之generator函数
相信很多学js的人都看过es6,我也是最近才看的es6标准.下面我来说一下我对es6笼统的看法,如有不对欢迎评论交流. js有很长很长的历史,大家应该都有了解过.es6是15年发布的版本,由TC39主 ...