Required Remainder

简介: Required Remainder

文章目录

一、A. Required Remainder

总结


一、A. Required Remainder

本题链接:A. Required Remainder


题目:


A. Required Remainder


time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output


You are given three integers x,y and n. Your task is to find the maximum integer k such that 0≤k≤n that kmodx=y, where mod is modulo operation. Many programming languages use percent operator % to implement it.


In other words, with given x,y and n you need to find the maximum possible integer from 0 to n that has the remainder y modulo x.


You have to answer t independent test cases. It is guaranteed that such k exists for each test case.


Input

The first line of the input contains one integer t (1≤t≤5⋅1e4) — the number of test cases. The next t lines contain test cases.


The only line of the test case contains three integers x,y and n (2≤x≤1e9; 0≤y<x; y≤n≤1e9).


It can be shown that such k always exists under the given constraints.


Output

For each test case, print the answer — maximum non-negative integer k such that 0≤k≤n and kmodx=y. It is guaranteed that the answer always exists.


Example

input


7

7 5 12345

5 0 4

10 5 15

17 8 54321

499999993 9 1000000000

10 5 187

2 0 999999999

output

12339

0

15

54306

999999995

185

999999998

Note

In the first test case of the example, the answer is 12339=7⋅1762+5 (thus, 12339mod7=5). It is obvious that there is no greater integer not exceeding 12345 which has the remainder 5 modulo 7.


本博客给出本题截图:

6.png

题意:找到这么一个k使得k % x = yk的取值范围是0n,求k的最大值

TLE代码

#include <cstdio>
using namespace std;
int main()
{
    int t;
    scanf("%d", &t);
    while (t -- )
    {
        int x, y, n;
        scanf("%d%d%d", &x, &y, &n);
        for (int i = n; i >= 0; i -- )
            if (i % x == y)
            {
                printf("%d\n", i);
                break;
            }
    }
    return 0;
}

AC代码

#include <cstdio>
using namespace std;
int main()
{
    int t;
    scanf("%d", &t);
    while (t -- )
    {
        int x, y, n;
        scanf("%d%d%d", &x, &y, &n);
        int k = n % x;
        if (k >= y)
            printf("%d\n", n + y - k);
        else 
            printf("%d\n", n - x + y  -k);
    }
    return 0;
}

总结

简单数论小题,动手模拟一下即可

目录
相关文章
|
2月前
|
JavaScript API
required string parameter ‘XXX‘is not present 的几种情况
required string parameter ‘XXX‘is not present 的几种情况
404 0
|
9月前
|
API
code: 400, value is mandatory for this action
code: 400, value is mandatory for this action
1544 1
|
9月前
|
Java 数据库连接 Redis
Bean method ‘redisConnectionFactory‘ not loaded because @ConditionalOnClass did not find required c
Bean method ‘redisConnectionFactory‘ not loaded because @ConditionalOnClass did not find required c
57 0
|
2月前
|
NoSQL Redis 数据库
解决noauth authentication required异常
解决noauth authentication required异常
170 0
解决noauth authentication required异常
|
8月前
|
数据安全/隐私保护
“Authentication is required”
“Authentication is required”
673 2
|
8月前
Missing required prop: “modelValue“
Missing required prop: “modelValue“
GenImageInterleaved Wrong type of control parameter 1
GenImageInterleaved Wrong type of control parameter 1
|
11月前
|
Java Apache Spring
解决required a single bean, but 2 were found问题
背景:springboot整合shiro中自定义Realm时出现 错误描述 Parameter 0 of method getDefaultWebSecurityManager in cn.ken.springboot_shiro.config.ShiroConfig required a single bean, but 2 were foun
|
11月前
|
JSON 数据格式
Required request parameter ‘name‘ for method parameter type String is not present 报错解决方法
Required request parameter ‘name‘ for method parameter type String is not present 报错解决方法
3457 0
|
11月前
|
Oracle Java 关系型数据库
Error setting null for parameter #6 with JdbcType OTHER . Try setting a different JdbcType for this
Error setting null for parameter #6 with JdbcType OTHER . Try setting a different JdbcType for this
205 0