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. 怎样判断一个P2P平台是否靠谱?

    判断一个网站,是否靠谱,是有规律可循的,P2P平台算是个新兴的电商类网站.   网上欺诈类的网站,不限于P2P,实在是太多了,真的有必要总结下最关键的几个靠谱指标.   最关键的2个   1.创始人和 ...

  2. 学习redis--简介(一)

    1.什么是redis? Redis是使用c语言开发的一个高性能键值数据库.Redis通过键值类型来存储数据.它通过提供多种键值数据类型来适应不同场景的存储需求. 2.redis支持哪些数据类型 Key ...

  3. HDU 2077 汉诺塔IV 递归 通项公式

    刚刚做的HDU 2064很好找规律, 回忆一下: b[1] = 2; b[n] = b[n-1] *3 + 2; 可得b[n]= 3^n-1 不懂的传送门http://blog.csdn.net/mu ...

  4. 10.4 android输入系统_框架、编写一个万能模拟输入驱动程序、reader/dispatcher线程启动过程源码分析

    1. 输入系统框架 android输入系统官方文档 // 需FQhttp://source.android.com/devices/input/index.html <深入理解Android 卷 ...

  5. 3、C++快速入门

    参考书籍: C++程序设计教程_第二版_钱能    //篇幅较少,适合快速学习 C++ Primer Plus  第六版  中文版   //篇幅较大,讲的非常详细 C++一般必须包含的头文件是#inc ...

  6. VS无法访问IIS元数据库 您没有足够的特权访问计算机上的IIS网站

    进入windows\regedit.exe下的HKEY_CRRENT_USER\Software\Microsoft\Windows\CurrentVersion\Exploer\User Shell ...

  7. ORACLE表空间的备份与恢复策略

    转自原文如何进行ORACLE表空间的备份与恢复? 1.切换服务器归档模式,如果已经是归档模式可跳过此步: %sqlplus /nolog (启动sqlplus) SQL> conn / as s ...

  8. 【Codeforces Round #185 (Div. 2) C】The Closest Pair

    [链接] 链接 [题意] 让你构造n个点,去hack一种求最近点对的算法. [题解] 让x相同. 那么那个剪枝就不会起作用了. [错的次数] 在这里输入错的次数 [反思] 在这里输入反思 [代码] # ...

  9. gdb查看线程堆栈信息

    查看堆栈:gdb -quiet -batch -ex='thread apply all bt' -p pid查看运行位置:gdb -quiet -batch -ex='thread apply al ...

  10. C++学习笔记8-操作符&amp;指针

    1.  重载操作符 赋值操作符的返回类型应该与内置类型赋值运算返回的类型同样.内置类型的赋值运算返回对右操作数的引用,因此,赋值操作符也返回对同一类类型的引用.比如.Sales_item的赋值操作符能 ...