http://codeforces.com/contest/1029/problem/F

这道题真的一点都不难……………………………………………………

对于大矩形面积a+b,从差距最小的因数开始遍历,直到遇到第一个a、b中的任何一个,能变成一个矩形并能放在大矩形中(因为最后的大矩形的面积一定等于a+b,所以剩余空间一定可以填补),我们就找到了解。

 1 import java.util.*;
2
3 public class A {
4 public static void main(String[] args) {
5 Scanner io = new Scanner(System.in);
6 long a = io.nextLong(), b = io.nextLong(), c = a + b;
7 long min = 0, max = 0;
8
9 for (long i = (long) Math.sqrt(c); i >= 1; i--) {
10 if (c % i == 0) {
11 min = i;
12 max = c / i;
13
14 //当两个因数差距越来越大时,max的长度比min大一倍多,所以max妥妥超时
15 for (long j = min; j >= 1; j--) {
16 if (a % j == 0 && a / j <= max || b % j == 0 && b / j <= max) {
17 System.out.println((min + max) * 2);
18 return;
19 }
20 }
21 }
22 }
23
24 }
25 }

最新文章

  1. sessionid如何产生?由谁产生?保存在哪里?
  2. webapi 通过dynamic 接收可变参数
  3. 从WinCE到Linux
  4. iOS -- 神战
  5. 69道Spring面试题和答案
  6. Orchard官方文档翻译(十一) 使用Tags组织文本
  7. 程序员定制的中州韵(rime)windows版(小狼毫)微软双拼输入法
  8. Visual Studio 自定义控件不显示在工具箱
  9. 工具栏ToolStrip能触发焦点控件的Leave、Validating、DataError等事件以验证数据 z
  10. Linux-ubuntu
  11. ANT的安装和配置(windows)
  12. Windows 下 pip和easy_install 的安装与使用
  13. js scroll 教程
  14. jQuery语音播放插件
  15. qdoc 简介
  16. 关于LeetCode的Largest Rectangle in Histogram的低级解法
  17. numpy.squeeze()是干啥的
  18. 妙谈js回调函数的理解!
  19. luogu 2014 选课 树上背包
  20. 生产环境elasticsearch5.0报错IllegalArgumentException: number of documents in the index cannot exceed 2147483519的处理

热门文章

  1. BalticOI 2004 Sequence 题解
  2. mysql 1366 - Incorrect string value
  3. GitHub + Hexo 搭建个人博客网站
  4. Python 常用库函数
  5. Java自动装箱与拆箱
  6. 创建型模式 - 原型模式Prototype
  7. Fiddler抓手机APP包
  8. 重定向Kubernetes pod中的tcpdump输出
  9. ThinkPad E580 装Ubuntu系 系统无WIFI 解决办法
  10. ES6 01 简介