C. K-th Not Divisible by n(数学+思维) Codeforces Round #640 (Div. 4)

原题链接: https://codeforces.com/problemset/problem/1352/C

在这里插入图片描述

测试样例:

Input
2
3 7
4 12
Output
10
15

解题思路: 这道题是一道水题。对于这道题,我们可以以 a a a的倍数为分界线(这里认为0也是),那么之间相隔了 ( a − 1 ) (a-1) (a1)个不能被a整除,我们找第 k k k大的就是那么就找它在第 i i i个整数和第 ( i + 1 ) (i+1) (i+1)整数之间的第几个数。具体看代码。

AC代码:

/*
*邮箱:unique_powerhouse@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h>	//POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>  pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

ll a,b;
int t;
int main(){
	//freopen("in.txt", "r", stdin);//提交的时候要注释掉
	IOS;
	while(cin>>t){
		while(t--){
			cin>>a>>b;
			ll sum;
			int t=b/(a-1);
			if(t*(a-1)==b){
				sum=(t-1)*a+a-1;
			}
			else{
				sum=t*a+b-t*(a-1);
			}
			cout<<sum<<endl;
		}
	}
	return 0;
}
posted @ 2022-03-26 16:51  unique_pursuit  阅读(41)  评论(0)    收藏  举报