您的位置:首页 > 编程语言 > Go语言

Codeforces 630D Hexagons!

2016-04-09 20:25 483 查看
D. Hexagons!

time limit per test
0.5 seconds

memory limit per test
64 megabytes

input
standard input

output
standard output

After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights
of big squadrons of enemies on infinite fields where every cell is in form of a hexagon.

Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the
cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another.

It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the
game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted
after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells
away from a given cell.



Input

The only line of the input contains one integer n (0 ≤ n ≤ 109).

Output

Output one integer — the number of hexagons situated not farther than n cells away from a given cell.

Examples

input
2


output
19


观察图形,找规律

#include <iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;

int main()
{
long long n,sum;
while(~scanf("%I64d",&n))
{
if(n==0)
sum=1;
else
{
sum=n*(n+1)/2*6+1;
}
printf("%I64d\n",sum);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: