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;
    }
  • 相关阅读:
    Ignoring HTTPS certificates
    利用Httponly提升web应用程序安全性
    HttpUrlConnection java.net.SocketException: Software caused connection abort: recv failed
    DISPOSE_ON_CLOSE 和 EXIT_ON_CLOSE 的区别
    Swing多线程
    攒机知识积累
    数组最大子数组和
    fork()详解
    理解Socket编程【转载】
    STM32F407_LED代码
  • 原文地址:https://www.cnblogs.com/VectorLin/p/5147614.html
Copyright © 2011-2022 走看看