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;
    }
  • 相关阅读:
    centos7 安装svn, 同时支持 svn 和 http访问
    Maven单独构建多模块项目中的单个模块
    openfalcon agent 监控数据
    kubernetes 垃圾回收机制
    docker tomcat 已主机名为日志输出路径
    k8s mongodb 集群配置
    修改Centos7的网卡ens32 改为eth0
    jenkins发版脚本更新
    Git系列七之备份迁移 升级 恢复管理
    confluence wiki搭建使用
  • 原文地址:https://www.cnblogs.com/jhz033/p/7074365.html
Copyright © 2011-2022 走看看