codeforces 859B B. Lazy Security Guard

来源:互联网 发布:河南金汇鑫软件 编辑:程序博客网 时间:2024/06/07 23:34

B. Lazy Security Guard
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个街区,但他们让他选择哪些街区。那就是,你的朋友要走一个区域的周边地区正是N块。你的朋友很懒,希望你的帮助能找到符合要求的最短路线。这座城市的布局为正方形网格,规模很大,为了解决这个问题,它可以被认为是无限的。

其实看图就能明白,它是要求几个小正方形拼起来以后周长最小是多少

#include<bits/stdc++.h>using namespace std;int main(){int n;while(cin>>n){cout<<2*(ceil(2*sqrt(n)))<<endl;}}