B. DIV + MOD
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Not so long ago, Vlad came up with an interesting function:
- fa(x)=⌊xa⌋+xmodafa(x)=⌊xa⌋+xmoda, where ⌊xa⌋⌊xa⌋ is xaxa, rounded down, xmodaxmoda — the remainder of the integer division of xx by aa.
For example, with a=3a=3 and x=11x=11, the value f3(11)=⌊113⌋+11mod3=3+2=5f3(11)=⌊113⌋+11mod3=3+2=5.
The number aa is fixed and known to Vlad. Help Vlad find the maximum value of fa(x)fa(x) if xx can take any integer value from ll to rr inclusive (l≤x≤rl≤x≤r).
Input
The first line of input data contains an integer tt (1≤t≤1041≤t≤104) — the number of input test cases.
This is followed by tt lines, each of which contains three integers lili, riri and aiai (1≤li≤ri≤109,1≤ai≤1091≤li≤ri≤109,1≤ai≤109) — the left and right boundaries of the segment and the fixed value of aa.
Output
For each test case, output one number on a separate line — the maximum value of the function on a given segment for a given aa.
Example
input
Copy
5 1 4 3 5 8 4 6 10 6 1 1000000000 1000000000 10 12 8
output
Copy
2 4 5 999999999 5
Note
In the first sample:
- f3(1)=⌊13⌋+1mod3=0+1=1f3(1)=⌊13⌋+1mod3=0+1=1,
- f3(2)=⌊23⌋+2mod3=0+2=2f3(2)=⌊23⌋+2mod3=0+2=2,
- f3(3)=⌊33⌋+3mod3=1+0=1f3(3)=⌊33⌋+3mod3=1+0=1,
- f3(4)=⌊43⌋+4mod3=1+1=2f3(4)=⌊43⌋+4mod3=1+1=2
As an answer, obviously, f3(2)f3(2) and f3(4)f3(4) are suitable.
解题说明:此题是一道数学题,找规律求解即可。
#include<stdio.h>int main()
{int t, l, r, i, sum;scanf("%d", &t);while (t--) {scanf("%d%d%d", &l, &r, &i);if (l / i == r / i || (r + 1) % i == 0) {sum = r / i + r % i;}else{sum = (r / i - 1) + i - 1;}printf("%d\n", sum);}return 0;
}
B. DIV + MOD相关推荐
- abap 中的语法 div / mod 的用法区别
在abap的开发过程中,用到div./.mod的时候并不是很多,除非要进行数据处理的时候才有可能用到它们了,下面介绍一下他们之间的用法与区别: 1.div div是用于取两数相除的商的,c = a d ...
- Codeforces Round #705 (Div. 2) D. GCD of an Array 质因子分解 + stl维护
传送门 题意: 给nnn个数,让后qqq个操作,每次选择一个位置的数使其乘xxx,每次询问后输出所有数的gcdgcdgcd. 思路: 这个题思路算是比较好想的.首先就是一个计算方式即计算所有数的gcd ...
- Codeforces Round #776 (Div. 3) A B C D E
Codeforces Round #776 (Div. 3) A B C D E A. Deletions of Two Adjacent Letters Tip: Implementation.St ...
- 大佬带你深入浅出Lua虚拟机
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由鹅厂优文发表于云+社区专栏 作者:郑小辉 | 腾讯 游戏客户端开发高级工程师 写在前面:本文所有的文字都是我手工一个一个敲的,以及本文 ...
- MySQL 中的运算符
1.算数运算符 MySQL 支持的算术运算符包括加.减.乘.除和模运算. 运算符 作用 + 加法,获得一个或多个值的和 - 减法,从一个值中减去另一个值 * 乘法,得到两个或多个值的乘积 /,div ...
- 【Java Web开发指南】ELJSTL笔记
文章目录 今日内容 JSP: MVC:开发模式 EL表达式 JSTL 三层架构:软件设计架构 案例:用户信息列表展示 今日内容 1. JSP:1. 指令2. 注释3. 内置对象2. MVC开发模式 3 ...
- MYSQL数据库——mysql的数据类型和运算符
一.数据类型和运算符 数据库表是由多列字段构成,每一个字段都是表的一个属性,每一列都指定了不用的数据类型.指定了数据类型之后,也就决定了向字段内插入的数据的内容.例如,插入的是数字的时候,既可以将它们 ...
- 数据库MYSQL学习系列二
2.1-MySQL数据类型 Number不止一种 ××× 浮点型 ××× INT SMALLINT MEDIUMINT BIGINT type Storage Minumun Value Maximu ...
- sql item_map
with /*SELECT 2 as lev, 1.0 as powerunion all select 3,1.9,union all select 4,2.5, ... */ -- lev_inf ...
最新文章
- 虚拟机下Linux安装图解之三:Linux发行版本之Red Hat 9 安装
- 探索--是测试的必须品
- matlab微分方程组边值,matlab求解常微分方程边值问题的方法
- node.js常见的模块
- oracle基于时间恢复整个数据库
- 翻译:用户变量(User-Defined Variable)(已提交到MariaDB官方手册)
- c语言找出公共子字符串,经典C语言面试题:求解最大公共子串
- 万网与阿里巴巴业务关系图解
- 字符串相似度匹配算法python_算法字符串相似度得分/哈希
- man 输出的帮助信息输出到文件中
- 中文命名实体识别,HMM,CRF,BiLSTM,BiLSTM+CRF的具体实现
- Atitit webshell选型 1. PHP Shell 2.4	1 1.1. 设置密码	4 2. 测试切换目录	4 2.1. 自己实现	5 1.PHP Shell 2.4 Please co
- linux用户名不在sudoers,如何修复“用户名不在sudoers文件中。这个事件将报告“在Ubuntu...
- 2021国内地址数据库表mysql
- 【今日CV 计算机视觉论文速览 第144期】Wed, 17 Jul 2019
- Python学习笔记-2017.5.4thon学习笔记-2017.5.19
- 计算机音乐有哪些优势,谈谈用电脑听无损音乐的好处
- 拿信用卡套个首付买房子——引火自焚
- parameterType的用法
- 案例研究:中国金融科技50强之“安心de利”风控模式