偶遇超强hack拼尽全力无法战胜
查看原帖
偶遇超强hack拼尽全力无法战胜
1397429
QHC_Si101楼主2025/5/4 09:29
#include<bits/stdc++.h>
using namespace std;
const int N=500;
long long ans[N],s[N],mo,cn;
int dep;

inline long long read() {
    long long x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9') {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}

inline void write(long long x) {
    if(x<0) {
        putchar('-');
        x=-x;
    }
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

inline long long gcd(long long a,long long b) {
    return b==0?a:gcd(b,a%b);
}

inline void dfs(long long x,long long y,int d) {
    if(dep==d) {
        s[d]=y;
        if(x==1&&s[d]>s[d-1]&&ans[dep]>s[dep]) memcpy(ans,s,sizeof(s));
        return;
    }
    for(int i=max(s[d-1]+1,y/x+1); i<(dep-d+1)*y/x; i++) {
        long long b=y*i;
        long long a=x*i-y;
        long long w=gcd(a,b);
        a/=w, b/=w;
        s[d]=i;
        if(s[d]==s[d-1]) break;
        dfs(a,b,d+1);
    }
}

int main() {
    long long i=0;
    cn=read(), mo=read();
    i=gcd(cn,mo);
    cn/=i, mo/=i;
    for(dep=2;; dep++) {
        ans[1]=0;
        s[0]=0;
        ans[dep]=2e9;
        dfs(cn,mo,1);
        if(ans[1]!=0) break;
    }
    for(int j=1; j<=dep; j++) {
        write(ans[j]);
        putchar(' ');
    }
    return 0;
}
2025/5/4 09:29
加载中...