题目链接:http://codeforces.com/problemset/problem/859/B
题意:要你求n个正方形的最小周长
思路:直接找规律了,具体看代码
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;
const int maxn = 1e6 + 5;
const int mod = 1e8 + 7;
int n;
int a[maxn];
int main() {
//freopen ("in.txt", "r", stdin);
a[0]=2;
int x=1;
int flag=1;
int t=0;
for (int i=1;i<=maxn;i++){
if (i==flag){
a[i]=a[i-1]+2;
t++;
flag=x+i;
if (t==2){
t=0;
x++;
}
}
else a[i]=a[i-1];
}
scanf ("%d",&n);
cout<<a[n]<<endl;
return 0;
}