Sort by

recency

|

1682 Discussions

|

  • + 0 comments

    int a = n; int d = 0; while(a>0){ int rem = a%10; if(rem != 0 && n % rem ==0){ d++; } a = a/10; } return d;

  • + 0 comments

    C# solution:

    public static int findDigits(int n)
    {
        int divisors = 0;
        int test = n % 10;
        int remainder = n;
        while (remainder > 0)
        {
            if (test != 0)
            {
                if (n % test == 0)
                {
                    divisors++;
                }
            }
            remainder /= 10;
            test = remainder % 10;
        }
        return divisors;
    }
    
  • + 0 comments

    //JAVA15 import java.io.; import java.util.; import java.util.stream.*;

    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) {
        int count = 0;
        int original = n;
    
        while (n > 0) {
            int digit = n % 10;
            if (digit != 0 && original % digit == 0) {
                count++;
            }
            n /= 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();
    }
    

    }

  • + 0 comments

    optimal approach but first requesting other learner to understand the code first

    function findDigits(n) {
        // Write your code here
        let num = n
        let cnt = 0
        
        while(num > 0){
            const lastDigi = num % 10
            if(lastDigi !== 0 && (n % lastDigi === 0)){
                cnt++
            }
            num = Math.floor(num/10)
        }
        return cnt
    }
    
  • + 0 comments

    Easy Solution

    def findDigits(Num:int):
        numbers = list(str(Num))
        count = 0
        
        for num in numbers:
            num = int(num)
            if num == 0:
                continue
            elif Num % num == 0:
                count += 1
        return count