2021mrctf------nomore

因为 $\frac{y+1}{x}$ 是整数。

(1) 若 $y=x-1$ 

$A=1+(x-1)^{5}+1$

经计算 $x$ 无解

(2)若 $y=k*x-1$ 

$A=(x-1)^{7}+(k*x-1)^{5}+k$

由式子可知, $x,k$  和 $A$ 正向先关,且提示 $k$ 很小,所以可以考虑二分。效率 $O(klog_{2}^{x})$

A = 2235930885430590738951770802593215586722001521194365487273377655750584443688709547709496531484159367793509666612116139038917661713102981488722293426038029073850795986080412124312908732573382156365974821471629333126275130148211145598662897276781331183691743094904957217401055325352877284530068805608962270139656431076370452327497416723045785664344412694060886085511378779487559306015113302658964110922621164879307182468690182325142055960562810349297544601157473985262796723316777380726315782859115449976700612343978057140270903396910431420116573138154719798955123904805279320166126412714788508008881174164656203605409187705643395043643983135944514470267283183175620492198093264226038082725867230101096344723124629565311122528005863046865164876192248803940590219355154176343702897505891392317123983475290611327887699795851456183931854177169939743970260837586185988111368384484356413787993370384262996486824251003884057486063787194241555190688935624792041028246639984544749568167915235629185515957106136630401960066317998226671344793061752525215496195839080165952892472180997564802474095868944184005854120238623750555477937802107959321257495435617363809377093354132077991399603767147974592666019334636208414969819333321639542282741932229892501074615920120228860717401055433206357806353717291748096464569063777964784860874773660469621546777686833078007220613545223169043960754010332944526795605043595879174073360317477199909570141202125189377475655277483919081658123820105695508771837612756891055031293872293977244105248233915807603916034288916844336329883443200123825714530812637709561686224468031953278836676202928878535091578725509651544544672494980806630321114490828976895602038151224026672265830787863940762596976124958000977955469148027648603199590311852993367450800166591526272653355552342455506908317529193196174849749103073968182002498580115241030154502931088245539152380579199202750010140022979979488971008874424439325749039212427088023136971891092490697689178097172878439007028844083681030357488034860471042630885195387680286557424780235116405464735985082715745087677866688657626763753940919966662710093619034074861812080778855241391731006
maxn = 4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

def f(x,k):
    return pow(x-1,7)+pow(k*x-1,5)+k-A

def binary_search(l,r,k):
    while l<=r :
        mid = (l+r)//2
        res = f(mid,k)
        if res == 0 :
            return(mid,1)
        if res < 0:
            l=mid+1
        else:
            r=mid-1
    return (mid,f(mid,k) == 0)


k=2
while 1:
    (x,pd) = binary_search(1,maxn,k)
    if pd:
        print(x,k)
        break
    k=k+1

 

解得

x=3009497962071627970325880719364587885671010480057866287334251735956364570350347087026477982283392009667042015682364869764534877202626872343001563490279098970253786309533656152965171286503259912849977668331206169132653702870703716072003169079329188859516303445545911170476352380900189590650131003576924340724

k=84

secret=7754486886526049025

根据条件

$e^{3}+p^{3}+q^{3}==secret$

暴力枚举出  $e,p$ 判断 $q$ 是否符合条件

效率大概是 $O(e*1e5*logA) $ ( $1000000-3000000$ 的质数大概有 $1e5$ 个)

#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
const int N=3e6+5;
bool ispri[N];
int top,pri[N];
ull secret=7754486886526049025;
void getpri(){
    ispri[0]=1;
    for(int i=2;i<=3000000;i++){
        if(!ispri[i])pri[++top]=i;
        for(int j=1;j<=top&&i*pri[j]<=3000000;j++){
            ispri[i*pri[j]]=1;
            if(i%pri[j]==0)break;
        }
    }
    int now=0;
    for(int i=1;i<=top;i++){
        if(pri[i]>1000000)pri[++now]=pri[i];
    }
    top=now;
}
ull pow(int x){
    return (ull)x*(ull)x*(ull)x;
}
int calc(ull tmp){
    int l=1000000,r=3000000;
    if(tmp<pow(l)||tmp>pow(r))return 0;
    int mid;
    while(l<=r){
        mid=(l+r)>>1;ull res=pow(mid);
        if(res==tmp)return mid;
        if(res<tmp)l=mid+1;
        else r=mid-1;
    }
    return 0;
}
ull gcd(ull x,ull y){
    if(x==0)return y;
    return gcd(y%x,x);
}
int main(){
    getpri();
    for(int e=9000;e<=10000;e++){
        for(int i=1;i<=top;i++){
            ull tmp=(ull)secret-pow(pri[i])-pow(e);
            int q=calc(tmp);
            if(ispri[q])continue;
            int p=pri[i];
            ull phi=(ull)(p-1)*(q-1);
            if(gcd((ull)e,phi)!=1)continue;
            printf("e = %d\np = %d\nq = %d\n",e,p,q);
            return 0;
        }
    }
    return 0;
} 

 解得

e = 9509
p = 1076303
q = 1866989

 

posted @ 2021-04-19 13:21  Jessiejzy  阅读(127)  评论(1编辑  收藏  举报