#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
vector<long long> a;
vector<long long> s;
void solve(long long n, int i)//还剩下的基数个数 i总的X个数
{
if(i==1)
{
cout<<"X";
return;
}
int j;
for(j=i-1;j>=0;j--)
{
if(a[j]*a[i-1-j]<n)
{
n=n-a[j]*a[i-1-j];
continue;
}
break;
}
if(j==i-1)
{
cout<<"X(";
solve(n,i-1);
cout<<")";
}
else if(j==0)
{
cout<<"(";
solve(n,i-1);
cout<<")X";
}
else
{
long long l=(n+a[j]-1)/a[j];
long long r=(n-1)%a[j]+1;
cout<<"(";
solve(l,i-1-j);
cout<<")X(";
solve(r,j);
cout<<")";
}
}
int main()
{
a.push_back(1);//a[0]
s.push_back(1);
a.push_back(1);//a[1]
s.push_back(2);
long long sum_s=2;
for(int i=2;;i++)
{
long long sum=0;
for(int j=0;j<=i-1;j++)
sum += a[j]*a[i-1-j];
a.push_back(sum);
sum_s+=sum;
s.push_back(sum_s);
if(sum>500000000)
break;
}
#ifdef ONLINE_JUDGE
#else
ifstream cin("1.txt");
#endif
long long n;
while(cin>>n && n)
{
n++;
int i;
for(i=0;;i++)
if(s[i]<n && n<=s[i+1])
break;
solve(n-s[i], i+1);
cout<<endl;
}
return 0;
}
zoj 1062 综合题
最新推荐文章于 2017-07-21 09:33:44 发布