工号不够用了怎么办
标题:工号不够用了怎么办? | 时间限制:1秒 | 内存限制:262144K | 语言限制:不限
3020年,空间通信集团的员工人数突破20亿人,即将遇到现有工号不够用的窘境。
现在,请你负责调研新工号系统。继承历史传统,新的工号系统由小写英文字母(a-z)和数字(0-9)两部分构成。新工号由一段英文字母开头,之后跟随一段数字,比如"aaahw0001","a12345","abcd1","a00"。注意新工号不能全为字母或者数字,允许数字部分有前导0或者全为0。
但是过长的工号会增加同事们的记忆成本,现在给出新工号至少需要分配的人数X和新工号中字母的长度Y,求新工号中数字的最短长度Z。
现在,请你负责调研新工号系统。继承历史传统,新的工号系统由小写英文字母(a-z)和数字(0-9)两部分构成。新工号由一段英文字母开头,之后跟随一段数字,比如"aaahw0001","a12345","abcd1","a00"。注意新工号不能全为字母或者数字,允许数字部分有前导0或者全为0。
但是过长的工号会增加同事们的记忆成本,现在给出新工号至少需要分配的人数X和新工号中字母的长度Y,求新工号中数字的最短长度Z。
import java.util.*; public class Main{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); String in = scan.nextLine(); String[] input = in.split("\\s+"); long peopleNum = Long.parseLong(input[0]);//需要分配的人数 int charSize = Integer.parseInt(input[1]);//新工号英文字母的长度 double num1 = Math.pow(26,(double)charSize); int i = 1; long num2 = (long)num1 * 10; while(num2 < peopleNum){ i ++; num2 *= 10; } System.out.println(i); } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll x,y; cin>>x>>y; ll sum=1; while(y--)sum*=26; if(sum>=x)cout<<1<<endl; else{ int co=0; while(sum<x){ sum*=10; co++; } cout<<co<<endl; } }
#include <cmath> #include<iostream> using namespace std; int res(long x, int y) { long res, cnt = -1; res = ceil(x / pow(26, y)); for (;res - pow(10, cnt) > 0;cnt++); return (cnt <= 0 ? 1 : cnt); } int main() { long x; int y; cin >> x >> y; cout << res(x, y); return 0; }
def solve(x, y) z = 1 base = 26 ** y factor = 10 while true if base * factor >= x puts z return end z += 1 factor *= 10 end end while line = STDIN.gets x, y = line.split(' ').collect(&:to_i) solve(x, y) end // ruby