zoukankan      html  css  js  c++  java
  • G

    If we sum up every digit of a number and the result can be exactly divided by 1010 , we say this number is a good number.

    You are required to count the number of good numbers in the range from AA to BB , inclusive.

    Input

    The first line has a number TT (T10000T≤10000 ) , indicating the number of test cases.

    Each test case comes with a single line with two numbers AA and BB (0AB10180≤A≤B≤1018 ).

    Output

    For test case XX , output Case #X: first, then output the number of good numbers in a single line.

    Sample Input

    2
    1 10
    1 20

    Sample Output

    Case #1: 0
    Case #2: 1

    Hint

    The answer maybe very large, we recommend you to use long long instead of int.

    分析:题目中的数据很大,所以可以往找规律的方面考虑

    打表之后会发现,每10个数都会有一个符合要求的数

    如果第十个数(整除10的数)是符合要求的数 就再加一个

    代码如下:

    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <iostream>
    using namespace std;
    typedef long long ll;
    #define INF 0x7fffffff
    int main()
    {
        ll a,b,cnta,cntb,h,num,t;
        cin>>t;
        for(ll r=1;r<=t;r++)
        {
        cin>>a>>b;
            a=a-1;
            cnta=0;
            cntb=0;
            cnta=a/10;
            h=a-a%10;
            num=0;
            while(h>0)
            {
                num+=h%10;
                h=h/10;
            }
            if(num%10==0)
            cnta++;
            for(ll i=a-a%10+1;i<=a;i++)
            {
            //    puts("1");
                h=i;
                num=0;
                    while(h>0)
            {
                num+=h%10;
                h=h/10;
            }
                 if(num%10==0)
                   cnta++;
            }
            if(a<0)
            cnta=0;
            cntb=b/10;
                h=b-b%10;
            num=0;
            while(h>0)
            {
                num+=h%10;
                h=h/10;
            }
            if(num%10==0)
            cntb++;
            for(ll i=b-b%10+1;i<=b;i++)
            {
            
                h=i;
                num=0;
                    while(h>0)
            {
                num+=h%10;
                h=h/10;
            }
                 if(num%10==0)
                   cntb++;
            }
        //    cout<<cnta<<endl;
        //    cout<<cntb<<endl;
            printf("Case #%lld: %lld
    ",r,cntb-cnta);
        
    }
    }
  • 相关阅读:
    NOIP2015 D1 解题报告
    2017.10.2 国庆清北 D2T2 树上抢男主
    2017.10.6 国庆清北 D6T3 字符串
    2017.10.1 国庆清北 D1T2 两个逗比捉迷藏
    电压驱动和电流驱动
    电子管
    点亮板载LED
    ESP8266——一般控制方法
    ESP8266——CPU频率更改和深度睡眠模式
    ESP8266——ADC
  • 原文地址:https://www.cnblogs.com/a249189046/p/6738309.html
Copyright © 2011-2022 走看看