Create 1429.java

pull/22/head
Kirigaya Kazuto 2016-06-16 11:39:29 +08:00 committed by GitHub
parent 3757222b50
commit 54ad675a3b
1 changed files with 24 additions and 0 deletions

24
QUSTOJ/1429.java Normal file
View File

@ -0,0 +1,24 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int radix = in.nextInt();
String s = in.next();
StringBuffer s2 = new StringBuffer(s).reverse();
int cnt = 0;
long x = Long.valueOf(s, radix);
while(!s2.toString().equals(s) && cnt <= 30){
cnt++;
x += Long.valueOf(s2.toString(), radix);
s = Long.toString(x,radix);
s2 = new StringBuffer(s).reverse();
}
if(cnt > 30){
System.out.println("Impossible!");
} else {
System.out.println("STEP=" + cnt);
}
in.close();
}
}