import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
StringBuffer sb = new StringBuffer("");
String m="";
while((m=br.readLine())!=null){
int temp=minBase(m);
long sum=sum(m);
if(temp==1){
sb.append(2).append("\n");
}
else{
boolean flag=false;
while(!flag && temp<63){
if(sum%(temp-1)==0){
flag=true;
break;
}
temp++;
}
if(flag)
sb.append(temp).append("\n");
else
sb.append("such number is impossible!").append("\n");
}
}
System.out.print(sb);
}
static int minBase(String temp) {
int max=-1;
for(int i=0;i<temp.length();i++){
if(temp.charAt(i)>='A' && temp.charAt(i)<='Z' ){
if(max<temp.charAt(i)-'A'+10)
max=temp.charAt(i)-'A'+10;
}
else if(temp.charAt(i)>='a' && temp.charAt(i)<='z' ){
if(max<temp.charAt(i)-'a'+36)
max=temp.charAt(i)-'a'+36;
}
else if(temp.charAt(i)>='0' && temp.charAt(i)<='9' ){
if(max<temp.charAt(i)-'0')
max=temp.charAt(i)-'0';
}
}
return max+1;
}
static long sum(String temp) {
long sum=0;
for(int i=0;i<temp.length();i++){
if(temp.charAt(i)>='A' && temp.charAt(i)<='Z' ){
sum+=temp.charAt(i)-'A'+10;
}
else if(temp.charAt(i)>='a' && temp.charAt(i)<='z' ){
sum+=temp.charAt(i)-'a'+36;
}
else if(temp.charAt(i)>='0' && temp.charAt(i)<='9' ){
sum+=temp.charAt(i)-'0';
}
}
return sum;
}
}
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
StringBuffer sb = new StringBuffer("");
String m="";
while((m=br.readLine())!=null){
int temp=minBase(m);
long sum=sum(m);
if(temp==1){
sb.append(2).append("\n");
}
else{
boolean flag=false;
while(!flag && temp<63){
if(sum%(temp-1)==0){
flag=true;
break;
}
temp++;
}
if(flag)
sb.append(temp).append("\n");
else
sb.append("such number is impossible!").append("\n");
}
}
System.out.print(sb);
}
static int minBase(String temp) {
int max=-1;
for(int i=0;i<temp.length();i++){
if(temp.charAt(i)>='A' && temp.charAt(i)<='Z' ){
if(max<temp.charAt(i)-'A'+10)
max=temp.charAt(i)-'A'+10;
}
else if(temp.charAt(i)>='a' && temp.charAt(i)<='z' ){
if(max<temp.charAt(i)-'a'+36)
max=temp.charAt(i)-'a'+36;
}
else if(temp.charAt(i)>='0' && temp.charAt(i)<='9' ){
if(max<temp.charAt(i)-'0')
max=temp.charAt(i)-'0';
}
}
return max+1;
}
static long sum(String temp) {
long sum=0;
for(int i=0;i<temp.length();i++){
if(temp.charAt(i)>='A' && temp.charAt(i)<='Z' ){
sum+=temp.charAt(i)-'A'+10;
}
else if(temp.charAt(i)>='a' && temp.charAt(i)<='z' ){
sum+=temp.charAt(i)-'a'+36;
}
else if(temp.charAt(i)>='0' && temp.charAt(i)<='9' ){
sum+=temp.charAt(i)-'0';
}
}
return sum;
}
}
No comments:
Post a Comment