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. 【POJ 1226】Substrings

    [链接]h在这里写链接 [题意] 给你n个字符串. 让你找一个字符串s. 设s'为这个字符串的逆序. 要求s或者s'在每个字符串里都能够找得到. 并且要求s的长度最长. 求出这个最长的串的长度. [题 ...

  2. spark 编程教程

      参考: 英文:https://spark.apache.org/docs/latest/programming-guide.html 中文:http://www.cnblogs.com/lujin ...

  3. php实现变态跳台阶(记忆化递归)

    php实现变态跳台阶(记忆化递归) 一.总结 1.本题思路(分类讨论思路,注意初始值和边界值):第一步如果1,那剩下的就是jumpFloorII($number-1)(下面jumpFloorII以j表 ...

  4. 《今天你买到票了吗?——从铁道部12306.cn站点漫谈电子商务站点的“海量事务快速处理”系统》

    <今天你买到票了吗?--从铁道部12306.cn站点漫谈电子商务站点的"海量事务快速处理"系统> 首发地址: http://bbs.hpx-party.org/thre ...

  5. php中模拟多继承如何实现

    php中模拟多继承如何实现 一.总结 一句话总结:其实你继承别人也是想调用别人类里面的方法和属性,所以可以这样做:这本类中创建目标类的对象,然后通过这个对象来调用方法和属性,这样比继承来的方便. 二. ...

  6. GDB(十)--调试正在运行的进程

    我编写了一个循环: long i;    for (i = 0; i < 999999; i++) {        mt.a += 1;        sleep(1);    }把它编译成a ...

  7. vscode visual studio code svn 小乌龟 快捷键设置

    首先要安装svn小乌龟 然后安装vs code的svn插件TortoiseSVN for VS Code 文件->首选项->键盘快捷方式->搜索svn->找到相应命令然后设置快 ...

  8. Java 字符转Unicode

    static String unicode2String(String unicodeStr) { StringBuffer sb = new StringBuffer(); String str[] ...

  9. 移动web处理input输入框输入银行卡号四位一空格

    由于项目上有需求要求输入银行卡号四位一空格的需求,改过好几版发现都有bug,最后优化了一版看起来效果还行,发帖留存. 难点是从中间插入和删除处理光标问题. 首先需要用到获取光标和设置光标的方法. // ...

  10. [Angular2] Map keyboards events to Function

    The idea is when we tape the arrow keys on the keyboard, we want the ball move accodingly. const lef ...