声网2021校招JAVA业务后台(3.9-3.11 ​)

整体考的相对基础,分为10道单选(30分),5道多选(20分),2道编程,一道lc中等,一道简单,分别是

关于1015,不知道为什么通过率始终只有0.8。。。
public class MinThree {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
        
		int count = 1;
		int[] tmp = getOneCount(n);
		int remainder = n / tmp[0];//除以全为1的最大因子后的余数
		long res = 1;
        //超出long边界则跳出循环
		long bound = Long.MAX_VALUE / 10;
        
		if (n % 2 != 0 && n % 5 != 0) {
			while (res % remainder != 0) {
				if (res > bound) break;
				res = 10 * res + 1;
				count++;
			}
			System.out.println(count + tmp[1]);
		} else {
            System.out.println(-1);
        }
	}

    //返回能被整除并且全为1的因子和该因子位数,用于优化类似9999之类的数
	public static int[] getOneCount(int n) {
		int res = 1, maxFactor = 1, count = 0;
		while (res < n) {
			if (n % res == 0) {
				maxFactor = Math.max(maxFactor, res);
			}
			res = 10 * res + 1;
		}
		int tmp = maxFactor;
		while (tmp != 0) {
			tmp /= 10;
			count++;
		}
		if (maxFactor == 1) count = 0;

		return new int[]{maxFactor, count};
	}
}    


#笔试题型##声网Agora##Java工程师#
全部评论
没面试就是不想招人吧 就喜欢浪费你们时间😢
点赞 回复
分享
发布于 2021-04-13 18:34
楼主有面试邀请吗?
点赞 回复
分享
发布于 2021-04-16 13:17
联想
校招火热招聘中
官网直投
85分才能进面
点赞 回复
分享
发布于 2021-04-17 13:55

相关推荐

头像
03-05 09:50
C++
点赞 评论 收藏
转发
点赞 2 评论
分享
牛客网
牛客企业服务