1 条题解

  • 0
    @ 2026-4-27 9:48:35
    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define db double
    ll T=1,n,a=1,b=1,def,fed;
    void solve(){
    	cin>>n;
    	for(int i=2;i<=n;i++){
    		a=a*(ll)i+b*(ll)1;
    		b*=(ll)i;
    		ll gcdd=__gcd(a,b);
    		a/=gcdd,b/=gcdd;
    	}
    	a*=n;
    	ll gcdd=__gcd(a,b);
    	a/=gcdd,b/=gcdd;
    	if(b==1){
    		cout<<a;
    		return ;
    	}
    	ll zs=a/b,kkk=zs,kkkk=b;
    	a-=zs*b;
    	while(kkk){
    		def++;
    		kkk/=10;
    	}
    	while(kkkk){
    		fed++;
    		kkkk/=10;
    	}
    	for(int i=0;i<=def;i++) cout<<" ";
    	cout<<a<<endl;
    	cout<<zs<<" ";
    	for(int i=1;i<=fed;i++) cout<<"-";
    	cout<<endl;
    	for(int i=0;i<=def;i++) cout<<" ";
    	cout<<b;
    }
    int main(){
    //	freopen(".in","r",stdin);
    //	freopen(".out","w",stdout);
    	while(T--){
    		solve();
    	}
    	return 0;
    }
    
    • 1

    「SHOI 早期试题选」百事的世界杯之旅

    信息

    ID
    10496
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者