codeforces 948B

Primal Sport

数学题

给出条件,pi为素数,  pi < xi, xi<=xi+1, xi = k*pi-1(xi是pi-1的倍数),并且xi是大于等于xi-1的最小的数, 现在给出x2, 求最小的x0的取值

思路: 由x2可以推出x1的取值, 由x1可以推出x0, 具体方法为, 由 x2=k1*p1,  可推得, x1的取值为 (k1-1)*p1+1 到 x2, 同理可得x0的取值, 将x2素因子分解后枚举p1即可

 

#include "iostream"
#include "iomanip"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#pragma comment(linker, "/STACK:102400000,102400000")
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a,x) memset(a,x,sizeof(a))
#define step(x) fixed<< setprecision(x)<<
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ll long long
#define endl ("\n")
#define ft first
#define sd second
#define lrt (rt<<1)
#define rrt (rt<<1|1)
using namespace std;
const ll mod=1e9+7;
const ll INF = 1e18+1LL;
const int inf = 1e9+1e8;
const double PI=acos(-1.0);
const int N=1e5+100;

int primx2[10005], primx1[10005];
int divide(int t, int *prim) {
    int tot=0;
    for(int i=2;i*i<=t;i++) {
        if(t%i==0) {
            prim[++tot]=i;
            while(t%i==0)t/=i;
        }
    }
    if(t>1)prim[++tot]=t;
    return tot;
}

int ans = inf;
int main() {
    int x2; cin>>x2;
    int n2 = divide(x2, primx2);
    for(int i=1; i<=n2; ++i){
        int p1 = primx2[i], k1 = x2/p1;
        int s1 = (k1-1)*p1+1;
        for(int x1=s1; x1<=x2; ++x1){
            int n1 = divide(x1, primx1);
            for(int j=1; j<=n1; ++j){
                int p0 = primx1[j], k0 = x1/p0;
                int x0 = (k0-1)*p0+1;
                if(x0<3) continue;
                ans = min(ans, x0);
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

 

posted on 2018-03-17 20:57  lazzzy  阅读(245)  评论(2编辑  收藏  举报

导航