Given a number N. You need to write a program to count the number of digits in N which evenly divides N.
Input:
First line of input contains an integer T which denotes the number of test cases. T test cases follows. First line of each test case contains a single integer N.
Output:
For each test case in a new line print the total number of digits of N which evenly divides N.
Constraints:
1<=T<=200
1<=N<=105
Example:
Input:
3
12
1012
23
Output:
2
3
0
Your Code
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int x;
x=n;
//cout<<x<<endl;
int num=0;
while(n!=0)
{
int digit=n%10;
n=n/10;
//cout<<digit<<endl;
//cout<<x%digit;
if(digit!=0)
{
if(x%digit==0)
{
num++;
// cout<<num<<endl;
}
}
}
cout<<num<<endl;
}
}
Input:
First line of input contains an integer T which denotes the number of test cases. T test cases follows. First line of each test case contains a single integer N.
Output:
For each test case in a new line print the total number of digits of N which evenly divides N.
Constraints:
1<=T<=200
1<=N<=105
Example:
Input:
3
12
1012
23
Output:
2
3
0
Your Code
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int x;
x=n;
//cout<<x<<endl;
int num=0;
while(n!=0)
{
int digit=n%10;
n=n/10;
//cout<<digit<<endl;
//cout<<x%digit;
if(digit!=0)
{
if(x%digit==0)
{
num++;
// cout<<num<<endl;
}
}
}
cout<<num<<endl;
}
}