给你一个x xx进制和一个y yy进制( 2 ≤ x , y ≤ 62 ) (2 \leq x,y \leq 62)(2≤x,y≤62)和一个x xx进制下的大数z zz(最大可能是6 2 1 20 62^12062
1
20)然后把z zz转化为y yy进制下数并输出。其中′ A ′ − ′ Z ′ 'A'-'Z'
′
A
′
−
′
Z
′
分别表示10 − 35 10-3510−35,′ a ′ − ′ z ′ 'a'-'z'
′
a
′
−
′
z
′
分别表示36 − 61 36-6136−61。
Java的大数转化
import java.math.BigInteger;
import java.util.Scanner;
import java.lang.StringBuffer;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
int n, m;
String string;
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
m = scanner.nextInt();
string = scanner.next();
if (string.equals("0")) {
System.out.println(0);
return;
}
BigInteger biginteger = BigInteger.ZERO, flag = BigInteger.ONE, k = BigInteger.valueOf(n);
for (int i = string.length() - 1; i >= 0; i --) {
int t;
if (string.charAt(i) >= '0' && string.charAt(i) <= '9') {
t = string.charAt(i) - '0';
}
else if (string.charAt(i) >= 'A' && string.charAt(i) <= 'Z') {
t = string.charAt(i) - 'A' + 10;
}
else t = string.charAt(i) - 'A' + 4;
BigInteger num = BigInteger.valueOf(t);
num = num.multiply(flag);
biginteger = biginteger.add(num);
flag = flag.multiply(k);
}
String ans = "";
BigInteger v = BigInteger.valueOf(m);
while(biginteger.compareTo(BigInteger.ZERO) != 0) {
BigInteger modinteger = biginteger.mod(v);
int res = Integer.valueOf(String.valueOf(modinteger));
if (res >= 10) {
res -= 10;
if (res < 26) {
ans += (char)('A' + res);
}
else {
ans += (char)('A' + res + 6);
}
}
else {
ans += res;
}
biginteger = biginteger.divide(v);
}
StringBuffer sBuffer = new StringBuffer(ans);
ans = sBuffer.reverse().toString();
System.out.println(ans);
}
}
import java.math.BigInteger;
import java.util.Scanner;
import java.util.Stack;
public class Main{
static BigInteger ToNum(char x){
if(x>='0'&&x<='9')
return new BigInteger(String.valueOf(x));
if(x>='a'&&x<='z'){
return new BigInteger(String.valueOf((x-'a')+36));
}
if(x>='A'&&x<='Z'){
return new BigInteger(String.valueOf((x-'A')+10));
}
return null;
}
static char ToChar(BigInteger x){
int ok=Integer.parseInt(x.toString());
if(ok>=0&&ok<=9) return (char)('0'+ok);
if(ok>=10&&ok<=35) return (char)('A'+(ok-10));
if(ok>=36&&ok<=61) return (char)('a'+(ok-36));
return '#';
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int x,y;
x=sc.nextInt();
y=sc.nextInt();
String str=sc.nextLine();
BigInteger sum=new BigInteger("0");
BigInteger cnt=new BigInteger("1");
BigInteger base=new BigInteger(String.valueOf(x));
for(int i=str.length()-1;i>=0;i--){
//System.out.println(str.charAt(i));
if(str.charAt(i)==' ') continue;
BigInteger temp=ToNum(str.charAt(i)).multiply(cnt);
//System.out.println(temp.toString());
if(temp==null) continue;
sum=sum.add(temp);
cnt=cnt.multiply(base);
}
Stack<Character> st=new Stack<Character>();
BigInteger akk=new BigInteger(String.valueOf(y));
if(sum.equals(BigInteger.ZERO)){
System.out.print(0);
}else{
while(!sum.equals(BigInteger.ZERO)){
st.push(ToChar(sum.mod(akk)));
sum=sum.divide(akk);
}
while (!st.empty()){
System.out.print(st.pop());
}
}
}
}
import java.util.Scanner;
import java.math.BigInteger;
public class Main
{
public static void main(String args[])
{
String s="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int x,y;
String z;
Scanner cin = new Scanner(System.in);
x=cin.nextInt();y=cin.nextInt();z=cin.nextLine();
BigInteger sum=new BigInteger("0");
BigInteger base=new BigInteger(String.valueOf(x));
BigInteger by=new BigInteger(String.valueOf(y));
for(int i=1;i<z.length();i++)
{
for(int j=0;j<s.length();j++)
if(z.charAt(i)==s.charAt(j))
{
sum=sum.multiply(base);
sum=sum.add(new BigInteger(String.valueOf(j)));
break;
}
}
String ans="";
if(sum.equals(BigInteger.ZERO)) ans="0";
else
{
while(!sum.equals(BigInteger.ZERO))
{
int ok=Integer.parseInt(sum.mod(by).toString());
ans+=s.charAt(ok);
sum=sum.divide(by);
}
}
for(int i=ans.length()-1;i>=0;i--) System.out.print(ans.charAt(i));
}
}