- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Count divisors of n that have at-least one digit common with n in Java

We are given with a number let’s say, num and the task is to calculate the divisor of a given number thereby count the divisors of num that have at least one digit common with n.

**Input** − num = 24

**Output** − Count is 4

**Explanation − we will perform the following steps** −

Firstly, calculate the divisors of a given number

Divisors of 24 are − 1, 2, 3, 4, 6, 8, 12, 24

Secondly, check which divisor have at least one digit that matches with the digits of a number

2, 4, 12, 24 are the divisors that contain the digit that matches with the digits in a number

**Input** − num = 10

**Output** − Count is 2

**Explanation − we will perform the following steps **−

Firstly, calculate the divisors of a given number

Divisors of 24 are: 1, 2, 5, 10

Secondly, check which divisor have at least one digit that matches with the digits of a number

1 and 10 are the divisors that contain the digit that matches with the digits in a number.

## Example

package test; import java.util.*; import java.util.List; import java.util.Scanner; public class Testdigit{ static int digitCheck(int m,int arr[]){ while (m > 0){ if (arr[m % 10]==1){ return(1); } m = m / 10; } return(0); } public static void main (String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int arr[] = new int[10]; int m = n; while (m > 0){ arr[m % 10] = 1; m = m / 10; } int count = 0; for (int i = 1; i <= Math.sqrt(n);i++){ if (n % i == 0){ if (digitCheck(i, arr)==1){ count++; } if (n / i != i){ if (digitCheck(n/i, arr)==1){ count++; } } } } System.out.println(ans); } }

## Output

If we run the above code we will get the following output −

Enter any number: 24 Count 5

- Related Questions & Answers
- Divisors of n-square that are not divisors of n in C++ Program
- Convert a number of length N such that it contains any one digit at least 'K' times in C++
- Count numbers from 1 to n that have 4 as a digit in C++
- C# program to check if two lists have at-least one element common
- Python program to check if two lists have at least one common element
- Count of all N digit numbers such that num + Rev(num) = 10^N - 1 in C++
- Count the numbers < N which have equal number of divisors as K in C++
- Count of m digit integers that are divisible by an integer n in C++
- Finding the longest Substring with At Least n Repeating Characters in JavaScript
- Count n digit numbers not having a particular digit in C++
- Count of Binary Digit numbers smaller than N in C++
- Numbers At Most N Given Digit Set in C++
- Count all possible N digit numbers that satisfy the given condition in C++
- Count elements that are divisible by at-least one element in another array in C++
- Count pairs in an array such that at least one element is prime in C++