社区讨论

90求条,必关

P1763埃及分数参与者 3已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@mm8w6hv5
此快照首次捕获于
2026/03/02 16:03
上周
此快照最后确认于
2026/03/05 18:15
5 天前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dep;
ll st[11],ans[11];
int flag;
int gcd(int x,int y){
    if(y==0)return x;
    return gcd(y,x%y);
}
void dfs(ll a,ll b,int x){
    if(x>dep){
        return;
    }
    if(a==1&&b>st[x-1]){
        st[x]=b;
        if(!flag||st[x]<ans[x]){
            for(int i=1;i<=dep;i++){
                ans[i]=st[i];
            }
        }
        flag=1;
        return;
    }
    ll l=max(b/a,st[x-1]+1);
    ll r=(dep-x+1)*b/a;
    if(flag&&r>=ans[dep]){
        r=ans[dep]-1;
    }
    for(ll i=l;i<r;i++){
        st[x]=i;
        ll gc=gcd(a*i-b,b*i);
        dfs((a*i-b)/gc,b*i/gc,x+1);
    }
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int a,b;
    cin>>a>>b;
    ll c=gcd(a,b);
    a/=c;
    b/=c;
    st[0]=1;
    for(dep=1;dep<=10;dep++){
        dfs(a,b,1);
        if(flag){
            for(int i=1;i<=dep;i++){
                cout<<ans[i]<<' ';
            }
            break;
        }
    }
    return 0;
}

回复

4 条回复,欢迎继续交流。

正在加载回复...