C. The Legend of Freya the Frog

time limit per test

2 seconds

memory limit per test

256 megabytes

Freya the Frog is traveling on the 2D coordinate plane. She is currently at point (0,0)(0,0) and wants to go to point (x,y)(x,y). In one move, she chooses an integer dd such that 0≤d≤k0≤d≤k and jumps dd spots forward in the direction she is facing.

Initially, she is facing the positive xx direction. After every move, she will alternate between facing the positive xx direction and the positive yy direction (i.e., she will face the positive yy direction on her second move, the positive xx direction on her third move, and so on).

What is the minimum amount of moves she must perform to land on point (x,y)(x,y)?

Input

The first line contains an integer tt (1≤t≤1041≤t≤104) --- the number of test cases.

Each test case contains three integers xx, yy, and kk (0≤x,y≤109,1≤k≤1090≤x,y≤109,1≤k≤109).

Output

For each test case, output the number of jumps Freya needs to make on a new line.

Example

Input

Copy

复制代码

3

9 11 3

0 10 8

1000000 100000 10

Output

Copy

复制代码
8
4
199999

Note

In the first sample, one optimal set of moves is if Freya jumps in the following way: (0,00,0) →→ (2,02,0) →→ (2,22,2) →→ (3,23,2) →→ (3,53,5) →→ (6,56,5) →→ (6,86,8) →→ (9,89,8) →→ (9,119,11). This takes 8 jumps.

解题说明:此题是一道数学题,交替向上向右走,可以不走,请问到给定点需要走几次。由于可以走0步,所以向上走和向右走是相互独立的,只需要求出他们的最大值即可。注意走0步的移动也要统计在内。

cpp 复制代码
#include <iostream>
#include<algorithm>
using namespace std;

void solve()
{
	long long x, y, k;
	cin >> x >> y >> k;
	long long ansx = x / k + (x % k != 0), ansy = y / k + (y % k != 0);
	if (ansx > ansy)
	{
		cout << 2ll * ansx - 1 << endl;
	}
	else
	{
		cout << 2ll * ansy << endl;
	}
}
int main()
{
	int TT = 1;
	cin >> TT;
	while (TT--)
	{
		solve();
	}
	return 0;
}
相关推荐
堕落年代6 分钟前
小红书JS SDK签名过程
开发语言·javascript·ecmascript
MediaTea8 分钟前
Python:math 库函数手册(双曲函数)
开发语言·python
€81111 分钟前
Java入门级教程16——JUC的安全并发包机制
java·开发语言·juc的安全并发包机制·栅栏机制·闭锁机制·信号量机制·无锁机制
爱吃KFC的大肥羊42 分钟前
C++三大特性之“继承”
开发语言·c++
毕设源码-李学长1 小时前
计算机毕业设计java高校多媒体教室管理系统高校多媒体教室综合管理系统高校智能多媒体教室管理平台
java·开发语言·课程设计
先知后行。1 小时前
线程的创建.销毁
开发语言·c++·算法
鱼嘻1 小时前
西嘎嘎学习 - C++ 继承 - Day 10
开发语言·c++·学习·算法
孤廖1 小时前
从 “模板” 到 “场景”,用 C++ 磨透拓扑排序的实战逻辑
开发语言·c++·程序人生·算法·贪心算法·动态规划·学习方法
我有火的意志1 小时前
Liunx执行source /etc/profile 报错, -bash: HISTTIMEFORMAT: readonly variable
开发语言·bash·histtimeformat·readonly
Hello_Embed1 小时前
STM32HAL 快速入门(二十四):I2C 编程(一)—— 从 OLED 显示初识 I2C 协议
c语言·stm32·单片机·嵌入式硬件·学习