Problem description |
Integer sequences are very interesting mathematical objects. Let us examine a sequence generated with the use of two operations: doubling and “digit sorting”. The latter operation consists in ascending-order sort of the individual digits in the decimal representation of the argument. For example, “digit sorting” of number 5726 gives 2567. |
Input |
The first line contains an integer n, the number of sequence member to be calculated. (1<=n<= 2 147 483 647) |
Output |
The output file should contain a single integer k, the value of the n-th member of the sequence. |
Sample Input |
1 6 |
Sample Output |
1 23 |
是个水题,但是刚开始的时候完全没有发现到后面的数是一样的,所以纠结了很久……罚时很高的说……。所以碰到范围特别大的题,很可能存在小tipppp。然后就是在处理数字和字符的时候会有一点小技术吧。
#include <stdio.h>
#include <iostream>
#include <algorithm>
#define maxn 2300
using namespace std;
__int64 n;
char s[maxn];
int a[27];
int b[6]={155578,111356,122227,244445,48889,77789};
int comp(char a,char b)
{
return a>b;
}
void go()
{
int i,j,k;
int p,q,r,x,y;
a[1]=1;
for(i=2;i<=26;i++)
{
a[i]=a[i-1]*2;
p=a[i];
q=p%10;
r=p/10;
x=0;
while(q||r)
{
s[x++]=q+'0';
q=r%10;
r=r/10;
}
sort(s,s+x,comp);
s[x]='\0';
a[i]=0;
while(x--)
{
a[i]=a[i]*10+s[x]-'0';
}
}
}
int main()
{
go();
while(scanf("%d",&n)!=EOF)
{
if(n<=26 ) printf("%d\n",a[n]);
else
{
printf("%d\n",b[(n-27)%6]);
}
}
return 0;
}