All problems
0505EasyMath

Stamped Cloakroom Ticket

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3622Check Divisibility by Digit Sum and Product

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A cloakroom prints a positive whole number n on every ticket and stamps the lucky ones. Take the decimal digits of n as they are written, with no leading zeros. Add up those digits to get their total, multiply them together to get their product, and add the total to the product to get the ticket's key.

A ticket is stamped when n is divisible by its key. Return true if the ticket printed with n is stamped and false otherwise.

A ticket whose number contains the digit 0 has a digit product of 0, and 0 counts as divisible by any positive key, so such a ticket is stamped exactly when n is divisible by its digit total.

Examples

Example 1

Input
n = 4536
Output
true

The digits 4, 5, 3 and 6 add to 18 and multiply to 360, so the key is 378. Since 4536 is 12 times 378, the ticket is stamped.

Example 2

Input
n = 4537
Output
false

The digits 4, 5, 3 and 7 add to 19 and multiply to 420, so the key is 439, and 4537 leaves a remainder of 159 against it.

Example 3

Input
n = 1000000
Output
true

The digits add to 1 and multiply to 0, so the key is 1, and every whole number is divisible by 1.

Constraints

  • 1 <= n <= 10^6

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def is_stamped(n: int) -> bool:
Java
public boolean isStamped(int n)
September 7
Apply