整体考的相对基础,分为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}; } }
全部评论
(3) 回帖