数学问题
224. 工号不够用怎么办
这里说人数 0< X <=2^50 – 1,由于 long类型可以表示 64 位,可以使用 long 数据类型来表示2的50次方
import java.util.Scanner;
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
// 由小写英文字母(a-z)和数字(0-9)两部分
// 新工号由一段英文字母开头,之后跟随一段数字,比如”aaahw0001″,”a12345″,”abcd1″,”a00″。
// 新工号不能全为字母或者数字,允许数字部分有前导0或者全为0
Scanner in = new Scanner(System.in);
String[] split = in.nextLine().split(" ");
long X = Long.parseLong(split[0]); // 人数 0< X <=2^50 – 1
int Y = Integer.parseInt(split[1]) ; // 新工号中字母的长度Y 0< Y <=5 【26】
// 公式:X = 26 ^ Y * 10 ^ Z
long res = (long)Math.ceil(Math.log10(X / Math.pow(26, Y)));
if (res == 0){
System.out.println(1);
return;
}
System.out.println(res);
}
}