首页 > 其他 > 详细

【Codeforces 923A】Primal Sport

时间:2019-03-28 16:52:00      阅读:170      评论:0      收藏:0      [点我收藏+]

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


题意

【题解】


考虑怎么得到数字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

原文:https://www.cnblogs.com/AWCXV/p/10615848.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!