In the digital world geometric shapes are drawn using
pixels. A pixel is a square area of unit dimension. For this problem we say 2
pixels are connected if they share an edge or a vertex between them. This is
also called 8-connectivity. Your task is to find the maximum possible area of a
closed loop made up of A pixels (these are boundary pixels of the closed loop).
Area of a closed loop is the number of pixels which are completely inside the
loop or on the loop. Consider the example below:
For A = 4, you can make a close loop as follows -
This has an area of 5 with 4 pixels on the loop and 1 pixel completely inside
the loop.
Input:
First line contains an integer N,
the number of test cases.
Next N lines contain an integer A for that test case.
N <= 100
A <= 1000
Output:
Print N
lines with a single integer stating the maximum area of a closed loop.
Sample Input:
2
4
5
Sample Output:
5
6
Time Limit: 2 seconds
Memory Limit: 32 MB
#include<iostream>
using namespace std;
int main()
{
int fun(int);
int N,ans,A;
cin>>N;
while(N>0)
{
cin>>A;
ans=fun(A);
cout<<ans<<endl;
N--;
}
return 0;
}
int fun(int A)
{
if(A==0)
{
return 0;
}
else if(A==1)
{
return 1;
}
else if(A==2)
{
return 2;
}
else if(A==3)
{
return 3;
}
else if(A==4)
{
return 5;
}
else
{
return A + fun(A-4);
}
}