Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 4580 | Accepted: 2095 |
Description
{ 0-9,A-Z,a-z }
HINT: If you make a sequence of base conversions using the output of one conversion as the input to the next, when you get back to the original base, you should get the original number.
Input
Output
Sample Input
8 62 2 abcdefghiz 10 16 1234567890123456789012345678901234567890 16 35 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2 35 23 333YMHOUE8JPLT7OX6K9FYCQ8A 23 49 946B9AA02MI37E3D3MMJ4G7BL2F05 49 61 1VbDkSIMJL3JjRgAdlUfcaWj 61 5 dl9MDSWqwHjDnToKcsWE1S 5 10 42104444441001414401221302402201233340311104212022133030
Sample Output
62 abcdefghiz 2 11011100000100010111110010010110011111001001100011010010001 10 1234567890123456789012345678901234567890 16 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2 16 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2 35 333YMHOUE8JPLT7OX6K9FYCQ8A 35 333YMHOUE8JPLT7OX6K9FYCQ8A 23 946B9AA02MI37E3D3MMJ4G7BL2F05 23 946B9AA02MI37E3D3MMJ4G7BL2F05 49 1VbDkSIMJL3JjRgAdlUfcaWj 49 1VbDkSIMJL3JjRgAdlUfcaWj 61 dl9MDSWqwHjDnToKcsWE1S 61 dl9MDSWqwHjDnToKcsWE1S 5 42104444441001414401221302402201233340311104212022133030 5 42104444441001414401221302402201233340311104212022133030 10 1234567890123456789012345678901234567890
Source
#include<cstdio>
#include<iostream>
#include<cstring>
const int maxn=1000;
using namespace std;
int t[maxn],A[maxn];
char str1[maxn],str2[maxn];
int n,m;
void solve(char *str1,char *str2,int n,int m)
{
int i,len,k;
len=strlen(str1);
for(i=len;i>=0;i--)
{
t[len-1-i]=str1[i]-(str1[i]<58?48:str1[i]<97?55:61);
}
for(k=0;len;)
{
for(i=len;i>=1;i--)
{
t[i-1]+=t[i]%m*n;
t[i]/=m;
}
A[k++]=t[0]%m;
t[0]/=m;
while(len>0&&!t[len-1])
{
len--;
}
}
str2[k]=NULL;
for(i=0;i<k;i++)
{
str2[k-1-i]=A[i]+(A[i]<10?48:A[i]<36?55:61);
}
}
int main()
{
int T,i;
cin>>T;
for(i=1;i<=T;i++)
{
cin>>n>>m>>str1;
solve(str1,str2,n,m);
cout<<n<<" "<<str1<<endl;
cout<<m<<" "<<str2<<endl;
if(i!=T)
{
cout<<endl;
}
}
}