码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 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.

    解题说明:此题是一道数学题,找规律求解即可。

    1. #include
    2. int main()
    3. {
    4. int t, l, r, i, sum;
    5. scanf("%d", &t);
    6. while (t--)
    7. {
    8. scanf("%d%d%d", &l, &r, &i);
    9. if (l / i == r / i || (r + 1) % i == 0)
    10. {
    11. sum = r / i + r % i;
    12. }
    13. else
    14. {
    15. sum = (r / i - 1) + i - 1;
    16. }
    17. printf("%d\n", sum);
    18. }
    19. return 0;
    20. }

  • 相关阅读:
    [附源码]java毕业设计亿上汽车在线销售管理系统
    【Android-实战】1、Room 使用 Flow 和 collect() 监听数据库的变化、动态更新页面
    X11 Xlib截屏问题及深入分析三 —— 源码实现2
    完美PDF打印:PDFPrinting.NET Crack
    嵌入式C语言这一篇就够了
    【vue3源码】八、reactive——Collection的响应式实现
    bash简化if-else
    【Pytorch深度学习实战】(8)双向循环神经网络(BiRNN)
    MongoDB基础详解
    面试高潮季即将来袭,Android 开发者能否在其中鲤鱼跃龙门?
  • 原文地址:https://blog.csdn.net/jj12345jj198999/article/details/126336529
  • 最新文章
  • 【JVM】编译执行与解释执行的区别是什么?JVM 使用哪种方式?
    用 Hashids 优雅解决 C 端自增 ID 暴露问题
    V8引擎 精品漫游指南--Ignition篇(上) 指令 栈帧 槽位 调用约定 内存布局 基础内容
    LLVM Pass快速入门(四):代码插桩
    milkup:桌面端 markdown AI续写和即时渲染
    基于项目工程构建SBOM(软件物料清单)的研究
    鸿蒙应用开发UI基础第二节:鸿蒙应用程序框架核心解析与实操
    .NET 中如何快速实现 List 集合去重?
    扣子Coze实战:从0到1打造抖音+小红书热点监控智能体
    浅谈数据访问层
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号