-
Notifications
You must be signed in to change notification settings - Fork 111
/
solution.cpp
49 lines (36 loc) · 940 Bytes
/
solution.cpp
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
#include <bits/stdc++.h>
using namespace std;
// Implentation Part
int findDigits(int n) {
// first make num == n so that we can use num
// initially, number of divisors = 0
// in loop while num > 0
int num = n, x, count = 0;
while(num > 0){
// find last digit of num
// check whether it divides n or not
x = num % 10;
// if x divides n
// increase count by 1
if(x != 0 && n % x == 0)
count++;
num = num / 10;
}
return count;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
int t;
cin >> t;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
for (int t_itr = 0; t_itr < t; t_itr++) {
int n;
cin >> n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int result = findDigits(n);
fout << result << "\n";
}
fout.close();
return 0;
}