https://www.codechef.com/TNP62121/problems/TNP603

#PROBLEM LINK: CodeChef: Practical coding for everyone

Author: Setter’s name

Tester:Tester’s name

Editorialist:Editorialist’s name

DIFFICULTY : EASY

#PREREQUISITES : NIL

#PROBLEM :

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).

solution
#include <stdio.h>
int main()
{
int t;
scanf(“%d”,&t);
while(t–)
{
int n,u,count=0,temp;
scanf(“%d”,&n);
u=n;
while(u)
{
temp=u%10;
if(temp!=0)
{
if(n%temp==0)count++;
}
u=u/10;
}
printf(“%d\n”,count);
}
return 0;
}

EXPLANATION :

The number 12 is broken into two digits 1 and 2. When 12 is divided by either of those digits, the calculation’s remainder is 0; thus, the number of evenly-divisible digits in 12 is 2.
The number 1012 is broken into four digits 1, 2, 3 and 2. 1012 is evenly divisible by its digits 1, 1, and 2, but it is not divisible by 0 as division by zero is undefined; thus, our count of evenly divisible digits is 3.