close
題目概要:
找出 N(2~62) 進位的數字,並且剛好可以被N-1給整除。其中A~Z由10~35表示、a~z由36~61表示。
解題方向:
以10進位為例,每個位數相加如果是9的倍數,那麼就可以被9整除。
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Java | |
import java.util.*; | |
class uva10093{ | |
public static void main(String args[]){ | |
Scanner sc=new Scanner(System.in); | |
String st; | |
while(sc.hasNextLine()){ | |
st=sc.nextLine(); | |
char Ctemp[]=st.toCharArray(); | |
int sum=0; | |
int max=1; | |
for(char temp:Ctemp){ | |
int R=0; | |
if(temp>=48 && temp<=57){ | |
R=temp-48; | |
}else if(temp>=65 && temp<=90){ | |
R=temp-55; | |
}else if(temp>=97 && temp<=122){ | |
R=temp-61; | |
} | |
sum=sum+R; | |
if(R>max) max=R; | |
} | |
for(int i=max;i<=62;i++){ | |
if(i==62){ | |
System.out.println("such number is impossible!"); | |
break; | |
} | |
if(sum%i==0){ | |
System.out.println(i+1); | |
break; | |
} | |
} | |
} | |
} | |
} |
文章標籤
全站熱搜