Skip to content
Programming101
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programmingoneonone

Learn everything about programming

Hackerrank Find Digit problem solution

YASH PAL, 31 July 2024

In this Hackerrank Find Digits problem we have given an integer, and for each digit that makes up the integer determine whether it is a divisor or not and we need to count the number of divisors that occur within the integer.

Problem solution in Python programming.

T = int(input())


for t in range(T):
    i_value = int(input())
    c_value = [float(i) for i in str(i_value)]
    
    total = 0
    for c in c_value:
        if c == 0:
            continue
        if (i_value/c)%1 == 0:
            total += 1
    print(total)

Problem solution in Java Programming.

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

class Result {

    /*
     * Complete the 'findDigits' function below.
     *
     * The function is expected to return an INTEGER.
     * The function accepts INTEGER n as parameter.
     */

    public static int findDigits(int n) {
    // Write your code here
int r = n;
int count = 0;
while(r > 0){
    if(r % 10 != 0 && n % (r % 10) == 0) count++;
    r = r / 10;
}
return count;

    }

}

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

        int t = Integer.parseInt(bufferedReader.readLine().trim());

        IntStream.range(0, t).forEach(tItr -> {
            try {
                int n = Integer.parseInt(bufferedReader.readLine().trim());

                int result = Result.findDigits(n);

                bufferedWriter.write(String.valueOf(result));
                bufferedWriter.newLine();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        });

        bufferedReader.close();
        bufferedWriter.close();
    }
}

Problem solution in C++ programming.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

void solve() {
    int n;
    cin >> n;
    int nr = n;
    int counter = 0;
    while (nr > 0) {
        int c = nr % 10;
        nr = nr / 10;
        if (c != 0 && n % c == 0) {
            ++counter;
        }
    }
    cout << counter << endl;
}

int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i) {
        solve();
    }
    return 0;
}

Problem solution in C programming.

#include <stdio.h>
int main()
{
    int i,t;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
       unsigned long long n,n2;
       int i=0,term;
       scanf("%llu",&n);
       n2 = n;
       while(n2 > 0)
       {
           term = n2%10;
           if(term!= 0 && n%term==0) i++;
           n2 /= 10;
       }
       printf("%dn",i);
    }
    return 0;
}

Problem solution in JavaScript programming.

function processData(numbers) {
  var numbers = numbers.split('n');
  numbers.shift();
  
  var divs = numbers.map(function(n) {
    var count = 0;
    n.split('').forEach(function(d) {
      if(n%d === 0) {
        count++;
      }
    });
    return count;
  });
  
  console.log(divs.join('n'));
  
} 

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});

Algorithms coding problems solutions

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes