zoukankan      html  css  js  c++  java
  • Codeforces597A

    Description

    Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k.

    Input

    The only line contains three space-separated integers k, a and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).

    Output

    Print the required number.

    Sample Input

     
    Input
    1 1 10
    Output
    10
    Input
    2 -4 4
    Output
    5

    今天这道题算是一道水题,但是却给了我对取余的新认识,也促使我对乘除法的形象化认识,除法就是在一个单位内找到有多少个另一个单位个数,做这种图只需要把题意形象化就可以了

    此题分一下类就OK还有一点我觉得比较好的想法就是对1的处理本题用了-(a-1)/c==-(a/c)+1/c;只有当1时1/C才会起作用;

    #include<iostream>
    #include<stdio.h>
    using namespace std;
    
    int main()
    {
        long long a,b,c;
        cin>>c>>a>>b;
        long long ans = 0;
        if(a<=0&&b<=0)
        {
            swap(a,b);
            a = -a,b = -b;
        }
        if(a<=0&&b>=0)
        {
            ans = (-a)/c+b/c;
            ans ++;
        }
        else
        {
            ans = (b/c)-(a-1)/c;
        }
        cout<<ans<<endl;
    }
  • 相关阅读:
    nodejs安装autoprefixer
    nodejs安装Yui Compressor
    js捕捉回车事件
    支付宝服务窗前台页面规范
    html5 input type number 去掉加减号
    [USACO10HOL]赶小猪题解
    [USACO09FEB]改造路题解
    [HNOI2013]游走题解
    洛谷P1649 [USACO07OCT]障碍路线Obstacle Course BFS 最小转弯
    洛谷P1467 循环数 Runaround Numbers
  • 原文地址:https://www.cnblogs.com/VectorLin/p/5147614.html
Copyright © 2011-2022 走看看