题目描述
You are given two positive integers n and k. Print the k-th positive integer that is not divisible by n.
For example, if n=3, and k=7, then all numbers that are not divisible by 3 are: 1,2,4,5,7,8,10,11,13…. The 7-th number among them is 10.
Input
The first line contains an integer t (1≤t≤1000) — the number of test cases in the input. Next, t test cases are given, one per line.
Each test case is two positive integers n (2≤n≤109) and k (1≤k≤109).
Output
For each test case print the k-th positive integer that is not divisible by n.
样例
6
3 7
4 12
2 1000000000
7 97
1000000000 1000000000
2 1
10
15
1999999999
113
1000000001
1
首先我们先看1~k中第k个数是k如果n大于k 直接输出k 如果n小于k有一些数是会被n整除的
然后 我们再看1~n中 有n-1个数不会被n整除 所以 咱们就可以划分出很多 区间元素为n-1个的区间 咱们要求第k个数
让k除以n-1就可以判断k在那个区间 再让k%(n-1)就可以判断k是哪个区间第几个数 然后咱们在让n扩大k/(n-1)倍这里要注意当k%(n-1)等于0时候要特判一下 第k个数正好是第(n-1)个区间最后一个元素
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
if(n>k)
{
cout<<k<<endl;
}
else{
int a=k/(n-1);
int b=k%(n-1);
if(b==0)
{
cout<<n*a-1<<endl;
}
else{
cout<<n*a+b<<endl;
}
}
}
return 0;
}