CF924F.Minimal Subset Difference

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

We call a positive integer xx a kk -beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to kk . Each digit should belong to exactly one subset after the split.

There are nn queries for you. Each query is described with three integers ll , rr and kk , which mean that you are asked how many integers xx between ll and rr (inclusive) are kk -beautiful.

输入格式

The first line contains a single integer nn ( 1<=n<=51041<=n<=5·10^{4} ), indicating the number of queries.

Each of the next nn lines describes a query, containing three integers ll , rr and kk ( 1<=l<=r<=10181<=l<=r<=10^{18} , 0<=k<=90<=k<=9 ).

输出格式

For each query print a single number — the answer to the query.

输入输出样例

  • 输入#1

    10
    1 100 0
    1 100 1
    1 100 2
    1 100 3
    1 100 4
    1 100 5
    1 100 6
    1 100 7
    1 100 8
    1 100 9
    

    输出#1

    9
    28
    44
    58
    70
    80
    88
    94
    98
    100
    
  • 输入#2

    10
    1 1000 0
    1 1000 1
    1 1000 2
    1 1000 3
    1 1000 4
    1 1000 5
    1 1000 6
    1 1000 7
    1 1000 8
    1 1000 9
    

    输出#2

    135
    380
    573
    721
    830
    906
    955
    983
    996
    1000
    

说明/提示

If 1<=x<=91<=x<=9 , integer xx is kk -beautiful if and only if x<=kx<=k .

If 10<=x<=9910<=x<=99 , integer x=10a+bx=10a+b is kk -beautiful if and only if ab<=k|a-b|<=k , where aa and bb are integers between 00 and 99 , inclusive.

100100 is kk -beautiful if and only if k>=1k>=1 .

首页