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

题意:如图,当有n层时,问总共有多少个六边形
题解:观察图形发现第0层有1个六边形,第1层有6个 第2层12个依次类推第n层有6*(n-1)个,则 当有n层时总共有1+1*6+2*6+3*6+...+n*6个提取公因数6则
1到n的和为n*(n-1)/2
#include<stdio.h>       //d
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#define INF 0x3f3f3f
#define MAX 100100
#define LL long long
using namespace std;
int main()
{
LL n,m,j,i;
while(scanf("%lld",&n)!=EOF)
{
n=n*(n+1)/2;
m=n*6+1;
printf("%lld\n",m);
}
return 0;
}

  

codeforces 630D Hexagons!的更多相关文章

  1. codeforces 615E Hexagons (二分+找规律)

    E. Hexagons time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  2. Codeforces Round #338 (Div. 2) E. Hexagons 讨论讨论

    E. Hexagons 题目连接: http://codeforces.com/contest/615/problem/E Description Ayrat is looking for the p ...

  3. 【38.46%】【codeforces 615E】Hexagons

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  4. 【CodeForces 615E】Hexagons

    找规律. #include <cstdio> #include <iostream> #include <algorithm> #include <cstri ...

  5. Codeforces Round #313 (Div. 2) C. Gerald's Hexagon 数学

    C. Gerald's Hexagon Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/pr ...

  6. Codeforces Round #313 (Div. 1) A. Gerald's Hexagon 数学题

    A. Gerald's Hexagon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/p ...

  7. 【打CF,学算法——三星级】Codeforces Round #313 (Div. 2) C. Gerald&#39;s Hexagon

    [CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/C 题面: C. Gerald's Hexagon time limit per tes ...

  8. Codeforces Round #313 (Div. 2) C. Gerald&#39;s Hexagon(补大三角形)

    C. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. 【41.43%】【codeforces 560C】Gerald's Hexagon

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. input默认提示取消

    input 输入框有提示功能,当你之前输入过一些内容,你下次打入相关字符的时候,默认会有之前输入的一些相关的字符的提示,这个提示一般来说还是很好的,但是,有时候,我们想自己输入,不想要提示. 如果不需 ...

  2. git cheat sheet,git四张手册图

  3. UVa 1262 (第k字典序) Password

    题意: 给出两个6行5列的字母矩阵,一个密码满足:密码的第i个字母在两个字母矩阵的第i列均出现. 然后找出字典序为k的密码,如果不存在输出NO 分析: 我们先统计分别在每一列均在两个矩阵出现的字母,然 ...

  4. asp.net实现GZip压缩和GZip解压

    最近在开发一个网站doc.115sou.com,使用到了GZip压缩技术,经过多次搜索找到asp.net中用GZip对数据压缩和解压缩非常方便,当我第一次拿到这个类的时候却感觉很迷茫,无从下手.主要是 ...

  5. [swustoj 1023] Escape

    Escape     Description BH is in a maze,the maze is a matrix,he wants to escape! Input The input cons ...

  6. EF4.0和EF5.0增删改查的写法区别及执行Sql的方法

    EF4.0和EF5.0增删改查的写法区别 public T AddEntity(T entity) { //EF4.0的写法 添加实体 //db.CreateObjectSet<T>(). ...

  7. UVALive 3211 Now or later(2-sat)

    2-sat问题,一种在两种可能性中选择必然关系的问题. 推荐两篇论文,也是学2-sat公认比较好的材料.前者较好理解,后者需耐心看. http://www.google.com.hk/url?sa=t ...

  8. 06day1

    Rabbit Number 枚举 [问题描述] 设 S(N)表示 N 的各位数字之和,如 S(484)=4+8+4=16,S(22)=2+2=4.如果一个正整数 x满足 S(x*x)=S(x)*S(x ...

  9. Buffer cache 的调整与优化

    Buffer cache 的调整与优化 -============================== -- Buffer cache 的调整与优化(一) --==================== ...

  10. 常用UI布局

    1.LinearLayout(线性布局):将布局所包含的控件在线性方向上依次排列. <1>android:orientation 指定了排列方向(垂直方向(vertical).水平方向(h ...