#187. 判断一个数是否为自除数
判断一个数是否为自除数
Self-Dividing Number
Background
In the world of numbers, some possess unique properties. Today, we will explore a special type of number: the "self-dividing number."
Problem Description
We define a positive integer as a "self-dividing number" if every digit in the number divides into the number evenly. For example, 128 is a self-dividing number because 1, 2, and 8 all divide into 128 evenly. If a number contains the digit 0, it is not a self-dividing number, as 0 cannot divide anything evenly.
Hint: Use the modulo operator (%) to get the rightmost digit, and the integer division operator (/) to discard the rightmost digit.
Input Format
Input is given from standard input in the following format.
A positive integer .
Output Format
Output is printed to standard output in the following format.
Output
trueif is a self-dividing number; otherwise, outputfalse.
Sample
128
true
12
true
120
false
Sample Explanation
Sample 1: For the number 128:
- 1 divides 128 ()
- 2 divides 128 ()
- 8 divides 128 () All digits divide 128, so 128 is a self-dividing number.
Sample 2: For the number 12:
- 1 divides 12 ()
- 2 divides 12 () All digits divide 12, so 12 is a self-dividing number.
Sample 3: For the number 120:
- It contains the digit 0. According to the rule, it is not a self-dividing number.
Constraints
The time limit for each test case is 1 second, and the memory limit is 1024 KiB.