zoukankan      html  css  js  c++  java
  • FJNU-1155 Fat Brother’s prediction

    Description

    Fat Brother is a famous prophet, One day he get a prediction that disaster will come after X days. He is too nervous that sudden die. Fortunately he leave a note about number X after he died:

    X is a number of integer which can divided exactly by Y range in [L, R]

    You want to know what X is.

     

    Input

    There are multiple test cases. The first line of input contains an integer T (T <= 10000) indicating the number of test cases. For each test case:

    Contain 3 integer L, R, Y (1 <= L <= R <= 2^63 - 1, 1 <= Y <= 2^63 - 1)

     

    There are multiple test cases. The first line of input contains an integer T (T <= 10000) indicating the number of test cases. For each test case:

    Contain 3 integer L, R, Y (1 <= L <= R <= 2^63 - 1, 1 <= Y <= 2^63 - 1)

     

    Output

    Each case print a number X.

     

    Sample Intput

    2

    1 3 2

    3 10 3

    Sample Output

    1

    3


    即区间[L, R]中能被Y整除的数的数量。

    直接用 R/Y 减去 L/Y 即可,也就是1到R中能被Y整除的数的数量减去1到L中能被Y整除的数的数量,因为是闭区间,所以要注意L本身是否能被Y整除,如果可以,结果要+1.

    #include <iostream>
    using namespace std;
    
    int main(void)
    {
        int t;
        
        while(cin >> t)
        {
            while(t--)
            {
                long long l, r, y, num = 0;
                
                cin >> l >> r >> y;
                num += r/y-l/y;
                if(l%y == 0)
                {
                    num++;
                }
                cout << num << endl;
            }
        }
        return 0;
    }
    

    当给出的数的范围很大的时候要记得用 long long,如果是水题,这很有可能是一道找规律的题目,如本题。

  • 相关阅读:
    UIAction 公共界面访问控制(拦截控制)
    MD5加密
    SVN的简单用法
    Spring AOP基础之JDK动态代理
    Spring中的事务管理模块基础
    Spring添加Junit4支持
    Spring里面dbcp连接池的配置和使用
    vue.js自定义指令详解
    vue input输入框联想
    export ,export default 和 import 区别 以及用法
  • 原文地址:https://www.cnblogs.com/limyel/p/6600582.html
Copyright © 2011-2022 走看看