小编Nid*_*dhi的帖子

如何计算可被数字总和整除的数字?

以下是hackerearth提出的问题.这是问题问题的链接 !我在java和c中编写了它的解决方案,但是在提交的某些测试用例中超出了时间限制.没有参与者能够为所有测试用例解决这个问题.什么是最有效的解决方案?

题:

鲍勃喜欢DSD Numbers.DSD Number是一个可以用十进制表示的数字和整除的数字.

digitSum(n):n的位数之和(以十进制表示形式)

例如:n = 1234然后digitSum(n)= 1 + 2 + 3 + 4 = 10

DSD Number是数字n,使得n%digitSum(n)等于0

Bob要求Alice告诉范围[L,R]的DSD号码的数量.

约束:

1 <=测试用例<= 50

1 <= L <= R <= 10 ^ 9

样本输入

4
2 5
1 10
20 45
1 100

样本输出

4
10
9
33

Java中的代码:

class DSD {

public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new    InputStreamReader(System.in));
    PrintWriter out=new PrintWriter(System.out);
    int t=Integer.parseInt(br.readLine());
    while(t-->0){
    StringTokenizer st=new StringTokenizer(br.readLine());
    int …
Run Code Online (Sandbox Code Playgroud)

algorithm math optimization

5
推荐指数
1
解决办法
4603
查看次数

标签 统计

algorithm ×1

math ×1

optimization ×1