【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;
}

转载于:https://www.cnblogs.com/AWCXV/p/10615848.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值