文章目录

  • 一、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.

本博客给出本题截图

题意:找到这么一个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;
}

总结

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

Required Remainder相关推荐

  1. A. Required Remainder

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  2. Codeforces Round #653 (Div. 3)部分题解

    文章目录 A - Required Remainder B - Multiply by 2, divide by 6 C - Move Brackets D - Zero Remainder Arra ...

  3. Codeforces Round #653 (Div. 3)(A, B, C, D, E1详解)

    Codeforces Round #653 (Div. 3) Required Remainder Thinking(binary search) 既然是找最大值问题,我又懒得去推式子,于是我直接就上 ...

  4. Codeforces Round #653 (Div. 3)

    A.Required Remainder 二分 #include<iostream> #include<algorithm> using namespace std; int ...

  5. QR code 二维码基础入门教程(三)

    QR code 入门教程(三) 承接上文,我们已经说过了数据编码和纠错码的生成,接下来我们继续下面的步骤 结构化最终的数据 所谓的结构化(Structure),说白了就是如何把之前生成的数据排成一个比 ...

  6. MAC最详细配置rz/sz命令

    Mac服务器文件交互 在Mac中使用rz,sz命令去和服务器进行文件交互,下面介绍一下如何配置MAC上的rz,sz. 1.安装iterm2 Mac自带的终端是不支持lrzsz,需要下载Mac上强大的终 ...

  7. 转载一片Mac电脑iterm2配置rz、sz命令超级实用

    rz .sz 是什么意思? rz 即 recv-zmodem,receive zmodem 接收协议(对服务器),对本机表现为上传. sz 即 send-zmodem,send zmodem 发送协议 ...

  8. iterm2配置rz sz

    1.首先安装brew,参考:Mac 安装 brew_sun_boy的博客-CSDN博客 2.安装lrzsz : brew install lrzsz 3.下载必须文件 iterm2-recv-zmod ...

  9. Mac. 使用 lrzsz

    首先,介绍一下这两个命令. sz:将选定的文件发送到本地机器. rz:运行该命令会弹出一个文件选择窗口,从本地选择文件上传到服务器. 1.安装lrzsz 第一种安装方式: [root@msc ~]# ...

最新文章

  1. 上海计算机协会竞赛平台——整除
  2. 密码工具:crunch的使用
  3. java某个参数值设置为空_@PathVariable为空时指定默认值的操作
  4. HITS 算法(Hypertext Induced TopicSelection)
  5. Login控件在浏览器中打开时显示英文
  6. 基于ESP-IDF环境的ESP32-C3开发
  7. 中国石油焦市场供需态势及投资潜力预测报告2021年版
  8. C#中.snk文件的作用【转】
  9. python 实验七 字典与集合 (上)
  10. 服务器微信互通是什么意思,妄想山海微信区和QQ区互通吗,服务器互通数据详解...
  11. 【历史上的今天】6 月 17 日:术语“超文本”的创造者出生;Novell 首席科学家诞生;探索频道开播
  12. 2021-2027全球与中国3D产品可视化平台市场现状及未来发展趋势
  13. Android UID相关知识
  14. 匿名吐槽有风险,脉脉又被告了
  15. Leetcode 881:救生艇问题
  16. 【开发经验】md自动上传图片
  17. Liferay DXP数字体验平台,荣耀绽放:端对端的客户体验
  18. 如果我有一颗私人卫星……|潮科技有奖问答评论精选 ②
  19. java计算机毕业设计校园环境保护监督系统源程序+mysql+系统+lw文档+远程调试
  20. 基于Multisim的自动售货的电路课程设计

热门文章

  1. 前端程序猿必备的网站
  2. 设计模式----单利模式
  3. Hadoop-HDFS总结(五)
  4. 未来智安XDR与中科方德高可信服务器操作系统完成产品兼容性互认证
  5. realme手机配什么蓝牙耳机?realme蓝牙耳机推荐
  6. bch纠错码 码长8_密码学BCH纠错编码算法
  7. 利用pyecharts绘制新浪微博传播图(文末附完整代码地址)
  8. 歌对华为使用安卓设限,但物联网操作系统还有更大机会
  9. 58.union (联合查询)
  10. python日历节日表_python日历模块_Python日历模块| calendar()方法与示例