time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined:

Ayrat is searching through the field. He started at point (0, 0) and is moving along the spiral (see second picture). Sometimes he forgets where he is now. Help Ayrat determine his location after n moves.

Input

The only line of the input contains integer n (0 ≤ n ≤ 1018) — the number of Ayrat’s moves.

Output

Print two integers x and y — current coordinates of Ayrat coordinates.

Examples

Input

3

Output

-2 0

Input

7

Output

3 2

【题解】



规律题;



可以看到,每一圈的边数是等差数列;公差为6;

且边的长度和圈数有着对应的关系(除了>形的地方);

对于所给的n;

用二分搞出这是第几圈;

(an=6+(n-1)6,sn=(a1+an)n/2;->sn=3*n(n+1));

然后总数减去3*(key-1)*(key-1+1)key为n所在的圈数;

减掉之后的步数可以再模拟一下具体在哪个位置,找下规律就好;

坐标和圈数和剩余的步数mod圈数有关

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define lson L,m,rt<<1
#define rson m+1,R,rt<<1|1
#define LL long long using namespace std; //const int MAXN = x;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0); LL n; void input_LL(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t) && t!='-') t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} void input_int(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)&&t!='-') t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
input_LL(n);
if (n==0)
{
puts("0 0");
return 0;
}
LL l = 0,r = 1e9,m = 0;
while (l <= r)
{
LL mid = (l+r)>>1;
if (1LL*3*mid*(mid+1)<=n)
{
m = mid;
l = mid+1;
}
else
r = mid-1;
}
n-=3*m*(m+1);
if (n==0)
{
printf("%I64d 0\n",m*2);
return 0;
}
m++;
LL zc = n/m,yu = n % m;
//cout << zc << " "<<yu<<endl; switch (zc)
{
case 0:
printf("%I64d %I64d\n",2*m-yu,2*yu);
break;
case 1:
printf("%I64d %I64d\n",m-2*yu,2*m);
break;
case 2:
printf("%I64d %I64d\n",-m-yu,2*m-yu*2);
break;
case 3:
printf("%I64d %I64d\n",-2*m+yu,-2*yu);
break;
case 4:
printf("%I64d %I64d\n",-m+2*yu,-2*m);
break;
case 5:
printf("%I64d %I64d\n",m+yu,-2*m+yu*2);
break;
case 6:
printf("%I64d %I64d\n",2*m,0);
break;
}
return 0;
}

【38.46%】【codeforces 615E】Hexagons的更多相关文章

  1. 【CodeForces 615E】Hexagons

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

  2. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  3. 【38.02%】【codeforces 625B】War of the Corporations

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

  4. 【19.46%】【codeforces 551B】ZgukistringZ

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

  5. 【codeforces 46C】Hamsters and Tigers

    [题目链接]:http://codeforces.com/problemset/problem/46/C [题意] 给你一个长度为n的01串; 让你把所有的0放在一起,把所有的1放在一起; (即0都是 ...

  6. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  7. 【搜索】【并查集】Codeforces 691D Swaps in Permutation

    题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...

  8. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  9. 【链表】【模拟】Codeforces 706E Working routine

    题目链接: http://codeforces.com/problemset/problem/706/E 题目大意: 给一个N*M的矩阵,Q个操作,每次把两个同样大小的子矩阵交换,子矩阵左上角坐标分别 ...

随机推荐

  1. jQuery的实现原理和核心

    1.jQuery的实现原理 1)jQuery采用的是构造函数模式进行开发的,jQuery是一个类 2)上面说的常用的方法(CSS.属性.筛选.事件.动画.文档处理)都是定义在jQuery.protot ...

  2. jvisualvm 工具使用

    VisualVM 是Netbeans的profile子项目,已在JDK6.0 update 7 中自带(java启动时不需要特定参数,监控工具在bin/jvisualvm.exe). https:// ...

  3. UvaLive 6663 Count the Regions 离散化+DFS

    链接:http://vjudge.net/problem/viewProblem.action?id=49408 题意:在平面内给出若干个矩形,求出它们能将整个平面分成多少份. 思路:刚開始一眼看到认 ...

  4. Sql Server 删除所有表 脚本

    如果由于外键约束删除table失败,则先删除所有约束: --/第1步**********删除所有表的外键约束*************************/ DECLARE c1 cursor f ...

  5. 28、从零写UVC驱动之实现设置属性

    1. 先看APP以确定需要实现哪些接口xawtv.c: grabber_scan ng_vid_open//根据链表的设置和读取可以在xawtv中找到是调用v4l2_driver.open v4l2_ ...

  6. Bootstrap相关优质项目学习清单

    1:编码规范 by @mdo编写灵活.稳定.高质量的 HTML 和 CSS 代码的规范 http://codeguide.bootcss.com/ 2:快速.可靠.安全的依赖管理工具.Yarn 缓存了 ...

  7. 【u023】最长上升子序列(sequence)

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 非常经典的问题,拿来给大家练手了. 序列 { 1,2,...,n } 的一个子序列是指序列 { i1, ...

  8. Qt信号槽传递自定义类型参数(qRegisterMetaType)

    1 #include <QMetaType>//记得包含这个头文件 2 //my_type是我自己定义的类型 3 qRegisterMetaType<my_type>(&quo ...

  9. thinkphp5 tp5 获取模块名控制器名方法名

    <?php namespace app\index\controller; use think\Db; use think\Controller; class Base extends Cont ...

  10. mybatis逆向工程随笔

    mybatis框架简介和简单原理: mybatis本来是apache的一个开源的项目,后来迁移到了google,并且改名为mybatis. mybatis框架优点: 1.mybatis是最简单的持久化 ...