`%`

operator can be useful. For instance, `(N % 10)`

gives the units of `N`

) then check the divisibility. Doesn't look a daunting task to me.

See more:

In a far away Galaxy of Milky Way, there was a planet Tarth where the sport of Competitive Tiding was very popular. According to legends, there came a new setter who loved maths. Hence, he made TCDSAP (Todechef Certified Data Structure & Algorithm Programme) with questions involving math's problems. Given a positive number NN, you have to find if NN is a Harshad number or not. A number NN is called a "Harshad number" if and only if NmodK=0 NmodK=0, where KK denotes the sum of digits of NN. That is, NN should be divisible by the sum of its digits.

Input The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows. The first and only line of each test case contains one integer NN. Output For each test case, print a single line containing "Yes" or "No".

yes but it gives the wrong answer

Example Input 5 10 13 75 55640877376 3622056459435540 Example Output Yes No No Yes Yes Explanation Example case 1: (10mod(1+0))=(10mod1)=0(10mod(1+0))=(10mod1)=0 Hence it is harshad number. Example case 2: (13mod(1+3))=(13mod4)=1(13mod(1+3))=(13mod4)=1 Hence it is not a harshad number. Example case 3: (75mod(7+5))=(75mod12)=3(75mod(7+5))=(75mod12)=3 Hence it is not a harshad number.

Comments

Patrice T
14-Apr-22 2:47am

And the problem or question is ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900