Company: Drishti-Soft
Question: Check that the number can be divided by the sum of its digit.
Question: Check that the number can be divided by the sum of its digit.
Input:
The first line of input contains an integer T denoting the number of test cases.Then T test cases follow .Each test case consist of an integer N.
Output:
Print 1 if divisible else 0.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 100000
1 ≤ N ≤ 100000
Example:
Input
2
18
19170
2
18
19170
Output
1
1
1
1
Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Solution{
public static void main (String[] args) {
//code
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
for(int mi=0;mi<m;mi++){
int n= sc.nextInt();
int n1=n;
int len= Integer.toString(n).length();
int [] ar= new int [len];
for(int i=0;i<len;i++){
ar[i]=n%10;
n=n/10;
}
int sum=0;
for(int j=0;j<len;j++){
sum+=ar[j];
}
if(n1%sum==0){System.out.println(1);}
else{System.out.println(0);}
}
}
}
Comments
Post a Comment