- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindDigits.java
More file actions
Latest commit
54 lines (46 loc) · 1.51 KB
/
Copy pathFindDigits.java
File metadata and controls
54 lines (46 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Given an integer, N, traverse its digits (d1,d2,...,dn) and determine how many digits evenly divide N (i.e.: count the number of times N divided by each digit di has a remainder of 0). Print the number of evenly divisible digits.
Note: Each digit is considered to be unique, so each occurrence of the same evenly divisible digit should be counted (i.e.: for N=111, the answer is 3).
Input Format
The first line is an integer, T, indicating the number of test cases.
The T subsequent lines each contain an integer, N.
Constraints
1≤T≤15
0<N<109
Output Format
For every test case, count and print (on a new line) the number of digits in N that are able to evenly divide N.
*/
importjava.io.*;
importjava.util.*;
importjava.text.*;
importjava.math.*;
importjava.util.regex.*;
publicclassSolution {
publicstaticvoidmain(String[] args) {
Scannerin = newScanner(System.in);
intt = in.nextInt();
for(inta0 = 0; a0 < t; a0++){
intn = in.nextInt();
intrem=n%10;
intcount=0;
if(n%rem==0)
{
count++;
}
intdiv=n/10;
while(div>0)
{
rem=div%10;
if(rem!=0)
{
if(n%rem==0)
{
count++;
}
}
div=div/10;
}
System.out.println(count);
}
}
}