time limit per test 2 seconds

memory limit per test 256 megabytes

input standard input

output standard output

Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly N city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly N blocks. Your friend is quite lazy and would like your help to find the shortest possible route that meets the requirements. The city is laid out in a square grid pattern, and is large enough that for the sake of the problem it can be considered infinite.

Input

Input will consist of a single integer N (1 ≤ N ≤ 106), the number of city blocks that must be enclosed by the route.

Output

Print the minimum perimeter that can be achieved.

Examples

input

4

output

8

input

11

output

14

input

22

output

20

Note

Here are some possible shapes for the examples:

【翻译】有n个长度为1的正方形块拼在一起,求最小周长。

题解:
     ①先对n开根的出近似边长x。

     ②尝试周长:x*x ,x*(x+1), (x+1)*(x+1),只要块数大于n,输出最小值就可以了。

#include<stdio.h>
#include<math.h>
using namespace std;
int n,a;
int main()
{
scanf("%d",&n);
a=floor(sqrt(1.0*n)+0.0001);
if(a*a>=n)printf("%d\n",4*a);
else if(a*(a+1)>=n)printf("%d\n",4*a+2);
else if((a+1)*(a+1)>=n)printf("%d\n",4*a+4);return 0;
}//Paul_Guderian

【CF MEMSQL 3.0 B. Lazy Security Guard】的更多相关文章

  1. 【CF MEMSQL 3.0 D. Third Month Insanity】

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  2. 【CF MEMSQL 3.0 A. Declined Finalists】

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  3. 【CF MEMSQL 3.0 E. Desk Disorder】

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  4. 【CF MEMSQL 3.0 C. Pie Rules】

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  5. codeforces 14A - Letter & codeforces 859B - Lazy Security Guard - [周赛水题]

    就像title说的,是昨天(2017/9/17)周赛的两道水题…… 题目链接:http://codeforces.com/problemset/problem/14/A time limit per ...

  6. 【MemSQL Start[c]UP 3.0 - Round 1 B】 Lazy Security Guard

    [链接]h在这里写链接 [题意] 围成对应面积的方块最少需要多少条边. [题解] 有特定的公式的. 2*ceil(2*根号下(n)); -> 自己找下规律也很简单的. [错的次数] 0 [反思] ...

  7. 【CF edu 30 C. Strange Game On Matrix】

    time limit per test 1 second memory limit per test  256 megabytes input standard input output standa ...

  8. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  9. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

随机推荐

  1. 怎么用Python Flask模板jinja2在网页上打印显示16进制数?

    问题:Python列表(或者字典等)数据本身是10进制,现在需要以16进制输出显示在网页上 解决: Python Flask框架中 模板jinja2的If 表达式和过滤器 假设我有一个字典index, ...

  2. ctf题目writeup(8)

    2019.2.11 南京邮电的ctf平台: 地址http://ctf.nuptzj.cn/challenges# 他们好像搭新的平台了...我注册弄了好半天... 1. 签到题,打开网址: 查看一下页 ...

  3. c#vs连接SQL sever数据库入门操作

    对于需要连接数据库的项目,可以参考的简单初级代码.实现打开数据库,读入数据功能 using System; using System.Collections.Generic; using System ...

  4. vue---day02

    1. 全局组件的注册 - 创建根实例的时候,data可以是object,也可以是函数 - 创建组件的时候,data必须是函数 1.1 创建 Vue.component('global-componen ...

  5. Python3 利用pip安装BeautifulSoup4模块(Windows版)

    一.找到Python3的安装文件夹 二.将路径复制 三.Windows10 打开Windows PowerShell(管理员).Windows 8.8.1.7使用cmd 切换到相应目录 四.此目录下的 ...

  6. 【POJ】1008 Maya Calendar

    参考:https://blog.csdn.net/u011392408/article/details/28866779 https://blog.csdn.net/qq_36424540/artic ...

  7. 【Leetcode】Jewels and Stones

    Jewels and Stones Description You're given strings J representing the types of stones that are jewel ...

  8. python基础之socket套接字基础part2

    基于UDP的socket 面向无连接的不可靠数据传输,可以没有服务器端,只不过没有服务器端,发送的数据会被直接丢弃,并不能到达服务器端 1 #客户端 2 import socket 3 ip_port ...

  9. cloudera manager服务迁移(scm数据库在postgresql上,其他amon,rman,oozie,metastore等在mysql上)

    公司线上大数据集群,之前用的是公有云主机,现在换成了自己idc机房机器,需要服务迁移,已下为测试: 1.备份原postgresql数据库: pg_dump -U scm scm > scm.sq ...

  10. android 怎么判断activity 从哪里启动的

    有时候,你想要知道,有一个activity 从哪里启动的.怎么才能知道呢? 1.前提是,androidstadio 你下载了源码.找到你的activityBase的实现类,在startActivity ...