另外一道双倍经验都过了,这道就是过不了
#include <iostream>
#include <cstdio>
using namespace std;
struct flac
{
long long son,mom;
};
long long gcd(long long a,long long b) {while(b^=a^=b^=a%=b);return a;}
flac build(long long son,long long mom)
{
flac now;
now.mom=mom;
now.son=son;
return now;
}
flac sum(flac a,flac b)
{
flac now;
now.son=a.mom*b.son+b.mom*a.son;
now.mom=a.mom*b.mom;
long long g=gcd(now.son,now.mom);
now.son/=g;
now.mom/=g;
return now;
}
flac mul(flac a,long long n)
{
flac now;
now.son=a.son*n;
now.mom=a.mom;
long long g=gcd(now.son,now.mom);
now.son/=g;
now.mom/=g;
return now;
}
long long findsize(long long a)
{
long long ans=1;
for(long long i=1;i<=a;i*=10,ans++);
return ans;
}
void print(flac a)
{
if(a.mom==1)
{
cout<<a.son<<endl;
return ;
}
int dai=a.son/a.mom;
if(dai==0)
{
cout<<a.son%a.mom<<endl;
for(int i=1;i<=findsize(a.mom)-1;i++) cout<<'-';
cout<<endl<<a.mom<<endl;
}
else
{
for(int i=1;i<=findsize(dai)-1;i++) cout<<' ';
cout<<a.son%a.mom<<endl;
cout<<dai;
for(int i=1;i<=findsize(a.mom)-1;i++) cout<<'-';
cout<<endl;
for(int i=1;i<=findsize(dai)-1;i++) cout<<' ';
cout<<a.mom<<endl;
}
}
int main()
{
long long n;
while(cin>>n)
{
flac ans=build(0,1);
for(long long i=1;i<=n;i++)
{
ans=sum(ans,build(1,i));
}
ans=mul(ans,n);
print(ans);
}
}