首页 > 其他 > 详细

CodeForces 1374A.Required Remainder

时间:2020-07-04 17:20:17      阅读:41      评论:0      收藏:0      [点我收藏+]

题意:你被给予了三个整数x,y和n。你的任务是找到一个最大的k,满足\(0 <= k <= n\),使得\(k\quad mod\quad x = y\)

分析:令k = p * x + y,满足k <= n,即\(p * x + y <= n\),那么\(p = \lfloor \frac{n - y}{x} \rfloor\),然后求出这个p之后,就可以求出k了。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;
using LL = long long;
int main()
{
	int t;
	scanf("%d", &t);

	while (t--)
	{
		LL x, y, n;
		cin >> x >> y >> n;
		LL p = (n - y) / x;

		if (p * x + y <= n)
		{
			cout << p * x + y << endl;
		}
		else
		{
			cout << p * (x - 1) + y << endl;
		}
	}
	

	return 0;
}

CodeForces 1374A.Required Remainder

原文:https://www.cnblogs.com/pixel-Teee/p/13235616.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!