codeforces 859B

来源:互联网 发布:大型网络3d手游2016年人气 编辑:程序博客网 时间:2024/06/08 13:32

 Lazy Security Guard

 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.


Example
Input
4
Output
8
Input
11
Output
14
Input
22
Output
20

Note
Here are some possible shapes for the examples:




题意:给出正方形的个数,拼到一起能够拼出最少的边;
思路:找规律,打表。
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<math.h>using namespace std;long long a[1100000];int main(){    int n;    a[0]=0;    a[1]=4;    a[2]=6;    long long t=8;    long long q=2;    int i=3;    while(1)    {        for(int j=0; j<q; j++)        {            a[i++]=t;        }        if(i>1000010)            break;        t+=2;        for(int j=0; j<q; j++)        {            a[i++]=t;        }        q++;        t+=2;        if(i>1000010)            break;    }//    for(int i=1;i<=25;i++)//        cout<<a[i]<<endl;    while(~scanf("%d",&n))    {        cout<<a[n]<<endl;    }}