题解 CF1374A 【Required Remainder】
比较裸,水估值
对于柿子:
\(k\) \(mod\) \(x\) = \(y\)
可以转化为:
\(k\) = \(x * now + y\)
再看取值范围:
\(0 <= k <= n\)
那么就是:
\(x * now + y <= n\)
\(x * now <= n - y\)
\(now <= \frac{(n - y)}{x}\)(下取整)
那么就很容易实现了
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#define maxn 50010
#define maxm 1000010
#define ls x << 1
#define rs x << 1 | 1
#define inf 10000000000
#define inc(i) (++ (i))
#define dec(i) (-- (i))
// #define mid ((l + r) >> 1)
#define int long long
#define XRZ 212370440130137957
#define debug() puts("XRZ TXDY");
#define mem(i, x) memset(i, x, sizeof(i));
#define Next(i, u) for(register int i = head[u]; i ; i = e[i].nxt)
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout);
#define Rep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i <= i##Limit ; inc(i))
#define Dep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i >= i##Limit ; dec(i))
int dx[10] = {1, -1, 0, 0};
int dy[10] = {0, 0, 1, -1};
using namespace std;
inline int read() {
register int x = 0, f = 1; register char c = getchar();
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
return x * f;
}
int x, y, n;
signed main() { int t = read();
while(t --) x = read(), y = read(), n = read() - y, printf("%lld\n", n / x * x + y);
return 0;
}