import
java.util.*;
class
GFG {
public
static
void
main(String[] args)
{
int
n =
7
;
int
[] arr
= {
833
,
3055
,
8521
,
360
,
2202
,
310
,
2111
};
System.out.println(funtionTOFindInt(arr, n));
}
public
static
int
funtionTOFindInt(
int
[] arr,
int
n)
{
Set<Integer>[] factDigits =
new
HashSet[
10
];
for
(
int
i =
1
; i <
10
; i++) {
int
fact = factorial(i);
factDigits[i] =
new
HashSet<>();
while
(fact !=
0
) {
factDigits[i].add(fact %
10
);
fact /=
10
;
}
}
int
count =
0
;
for
(
int
i =
0
; i < n; i++) {
int
x = arr[i];
while
(x >=
10
) {
x = getSum(x);
}
Set<Integer> digits = factDigits[x];
boolean
flag =
true
;
while
(arr[i] >
0
) {
int
dig = arr[i] %
10
;
if
(!digits.contains(dig)) {
flag =
false
;
break
;
}
arr[i] /=
10
;
}
if
(flag)
count++;
}
return
count;
}
public
static
int
factorial(
int
n)
{
return
(n ==
1
|| n ==
0
) ?
1
: n * factorial(n -
1
);
}
public
static
int
getSum(
int
n)
{
int
sum =
0
;
while
(n !=
0
) {
sum = sum + n %
10
;
n = n /
10
;
}
return
sum;
}
}