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,如果是水题,这很有可能是一道找规律的题目,如本题。

  • 相关阅读:
    数论学习笔记之欧拉函数
    [CQOI2014]危桥
    lspci -nnk
    linux 详解useradd 命令基本用法
    。 (有些情况下通过 lsof(8) 或 fuser(1) 可以 找到有关使用该设备的进程的有用信息)
    CentOS 7 设置默认进入字符界面
    下面附上top和sar的使用方法,方便参考! "top"工具
    Centos7/RHEL7 开启kdump
    Linux内存带宽的一些测试笔记
    调试测试
  • 原文地址:https://www.cnblogs.com/limyel/p/6600582.html
Copyright © 2011-2022 走看看