P1291 [SHOI2002]百事世界杯之旅-CSDN博客

admin 56 0

P1291 [SHOI2002]百事世界杯之旅-CSDN博客

  #include #define il inline #define ll long long #define For(i,a,b) for(int (i)=(a);(i)<=(b);(i)++) #define Bor(i,a,b) for(int (i)=(b);(i)>=(a);(i)--) using namespace std; ll n; ll top,bot=1,p,q,x,y; il ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} il ll num(ll x){ll tot=0;while(x)tot++,x/=10;return tot;} int main(){ ios::sync_with_stdio(0); cin>>n;top=n; For(i,2,n) x=i,y=n,p=gcd(x,y),x/=p,y/=p,top=top*x+bot*y,bot*=x,p=gcd(top,bot),top/=p,bot/=p; if(top%bot==0)printf("%lld",top/=bot); else{ p=num(bot),q=num(top/bot); For(i,1,q)printf(" "); printf("%lld

  %lld",top%bot,top/bot); while(p--)printf("-");printf("

  "); For(i,1,q)printf(" ");printf("%lld",bot); } return 0; }