常规训练第15轮A - Floor Number

常规训练第15轮A - Floor Number

Vasya goes to visit his classmate Petya. Vasya knows that Petya’s apartment number is n.

There is only one entrance in Petya’s house and the distribution of apartments is the following: the first floor contains 2 apartments, every other floor contains x apartments each. Apartments are numbered starting from one, from the first floor. I.e. apartments on the first floor have numbers 1 and 2, apartments on the second floor have numbers from 3 to (x+2), apartments on the third floor have numbers from (x+3) to (2⋅x+2), and so on.

Your task is to find the number of floor on which Petya lives. Assume that the house is always high enough to fit at least n apartments.

You have to answer t independent test cases.

Input
The first line of the input contains one integer t (1≤t≤1000) — the number of test cases. Then t test cases follow.

The only line of the test case contains two integers n and x (1≤n,x≤1000) — the number of Petya’s apartment and the number of apartments on each floor of the house except the first one (there are two apartments on the first floor).

Output
For each test case, print the answer: the number of floor on which Petya lives.

Example
Input
4
7 3
1 5
22 5
987 13
Output
3
1
5
77

这是一道思维题,已知房间号 n,和除第一层之外每层房间数x,求 Petya 住的楼层数,由题可知,第一层永远只有两间房,在第一层特殊处理 n-2,其余的层数为 n-x,直到n<=0为止。楼层范围小于1000

#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int i,n,x,t;
    cin>>t;
    while(t--)
    {
        cin>>n>>x;
        for(i=1;i<=1005;i++)
        {
            if(i==1)
        {
            n-=2;
        }
        else
        {
            n-=x;
        }
            if(n<=0)
            {
                cout<<i<<endl;
                break;
            }
        }

        }


    return 0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值