Find The Digits
Given an integer, , traverse its digits (1,2,...,n) and determine how many digits evenly divide (i.e.: count the number of times divided by each digit i has a remainder of ). 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 , the answer is ).
Input Format
The first line is an integer, , indicating the number of test cases.
The subsequent lines each contain an integer, .
Constraints
Output Format
For every test case, count and print (on a new line) the number of digits in that are able to evenly divide .
- Solution:
- Python3.6
t=int(input())
for I in range(t):
n=int(input())
k=str(n)
c=0
for j in k:
if(j=='0'):
continue
else:
if(n%int(j)==0):
c+=1
print(c)
- C++ Solution
#include<bits/stdc++.h>
#include<cstdlib>
using namespace std;
int main() {
int n;
cin>>n;
while(n--){
int a,cont=0;
cin>>a;
string b=to_string(a);
for(int i=0;i<b.size();i++){
if(b[i]=='0')continue;
int dv=b[i]-'0';
if(a%dv==0){
cont++;
}
}
cout<<cont<<endl;
}
}
- Java Solution
No comments: