码农知识堂 - 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. }

  • 相关阅读:
    Flutter中GetX系列六--GetxController使用详情
    【Unity学习笔记】第二十 · 物理引擎脉络梳理(数值积分、碰撞检测、约束解决)
    window10单机部署hbase-2.5.5-hadoop3
    vue:项目开发:在请求拦截器中处理loading加载 && 请求头(headers)的检验配置 && 接口文档出现的特殊符号处理的方式
    【USRP】通信之有线通信
    一文彻底搞懂ZAB算法,看这篇就够了!!!
    国学---佛系算吉凶~
    【JS】前端面试常见手写题总结
    浅析 C# Console 控制台为什么也会卡死
    Ubuntu中安装使用QEMU/KVM/virt-manager运行虚拟机
  • 原文地址:https://blog.csdn.net/jj12345jj198999/article/details/126336529
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号