题意:你被给予了三个整数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;
}