zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 23 C. Really Big Numbers 暴力

    C. Really Big Numbers
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than n.

    Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.

    Input

    The first (and the only) line contains two integers n and s (1 ≤ n, s ≤ 1018).

    Output

    Print one integer — the quantity of really big numbers that are not greater than n.

    Examples
    Input
    12 1
    Output
    3
    Input
    25 20
    Output
    0
    Input
    10 9
    Output
    1
    Note

    In the first example numbers 10, 11 and 12 are really big.

    In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).

    In the third example 10 is the only really big number (10 - 1 ≥ 9).

      题意:找出1-n内所有数字,数字要满足的条件:数字-每位数的和>=s;

    思路:每位数的和最多180,所有只需要暴力s,s+180区间,后面小于n的肯定满足条件;

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    #include<bitset>
    #include<time.h>
    using namespace std;
    #define LL long long
    #define pi (4*atan(1.0))
    #define eps 1e-4
    #define bug(x)  cout<<"bug"<<x<<endl;
    const int N=3e5+10,M=1e5+10,inf=2147483647,mod=1e9+7;
    const LL INF=1e18+10,MOD=1e9+7;
    
    LL sum(LL x)
    {
        if(x==0)return 0;
        return sum(x/10)+x%10;
    }
    int main()
    {
        LL n,s;
        scanf("%lld%lld",&n,&s);
        LL x=min(n,s);
        LL ans=0;
        for(LL i=s;i<=s+200;i++)
        {
            if(i<=n&&i-sum(i)>=s)
                ans++;
        }
        ans+=max(0LL,n-s-200);
        printf("%lld
    ",ans);
        return 0;
    }
  • 相关阅读:
    Luogu P4071 [SDOI2016]排列计数
    CF 961E Tufurama
    Luogu P2057 [SHOI2007]善意的投票
    Luogu P2756 飞行员配对方案问题
    POJ2151
    POJ 3349&&3274&&2151&&1840&&2002&&2503
    POJ 2388&&2299
    EZ 2018 03 30 NOIP2018 模拟赛(六)
    POJ 1459&&3436
    BZOJ 1001: [BeiJing2006]狼抓兔子
  • 原文地址:https://www.cnblogs.com/jhz033/p/7074365.html
Copyright © 2011-2022 走看看