Trains the technique from
LeetCode 507Perfect NumberThis 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 fastener plant describes a batch size as balanced when the batch can be rebuilt exactly from its own smaller shares.
A share of num is a positive whole number, strictly less than num, that goes into num leaving nothing over. Add up every share of num. When that running total lands on num itself, the batch size is balanced.
Given the batch size num, return true when it is balanced and false when it is not.
Example 1
The shares of 496 are 1, 2, 4, 8, 16, 31, 62, 124 and 248, and they add up to 496, so the batch size is balanced.
Example 2
The shares of 500 are 1, 2, 4, 5, 10, 20, 25, 50, 100, 125 and 250, which add up to 592. That total is not 500.
Example 3
1 has no share at all, since a share must be a positive whole number below 1. An empty total is 0, which is not 1.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def check_perfect_number(num: int) -> bool:public boolean checkPerfectNumber(int num)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.