第3题: Scanner in = new Scanner(System.in); int total = Integer.parseInt(in.nextLine()); for (int i = 0; i < total; i++) { String[] xy = in.nextLine().split(" "); long x = Long.parseLong(xy[0]); long y = Long.parseLong(xy[1]); long dist = Math.abs(x - y); if (dist == 0) { System.out.println(0); continue; } long n = 0; while (n * n <= dist) { n++; } n--; long left = dist - n * n; long add1 = left / n; long add2 = left % n; long ans = 2 * n - 1 + add1; if (add2 != 0){ ans += 1; } System.out.println(ans); }
点赞 8

相关推荐

05-19 19:57
蚌埠学院 Python
2237:Gpa70不算高,建议只写排名,个人技能不在多而在精,缩到8条以内。项目留一个含金量高的,减少间距弄到一页,硕士简历也就一页,本科不要写很多
实习,投递多份简历没人回...
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务