#187. 判断一个数是否为自除数

    ID: 187 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatAp-1gesp1循环结构条件结构

判断一个数是否为自除数

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

Output Format

Output is printed to standard output in the following format.

Output true if NN is a self-dividing number; otherwise, output false.

Sample

128
true
12
true
120
false

Sample Explanation

Sample 1: For the number 128:

  • 1 divides 128 (128÷1=128128 \div 1 = 128)
  • 2 divides 128 (128÷2=64128 \div 2 = 64)
  • 8 divides 128 (128÷8=16128 \div 8 = 16) All digits divide 128, so 128 is a self-dividing number.

Sample 2: For the number 12:

  • 1 divides 12 (12÷1=1212 \div 1 = 12)
  • 2 divides 12 (12÷2=612 \div 2 = 6) 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.