All problems
0574EasyMath

Balanced Batch Size

Tracked in this browser only
Write code

Trains the technique from

LeetCode 507Perfect Number

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

Examples

Example 1

Input
num = 496
Output
true

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

Input
num = 500
Output
false

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

Input
num = 1
Output
false

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.

Constraints

  • 1 <= num <= 10^8

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 check_perfect_number(num: int) -> bool:
Java
public boolean checkPerfectNumber(int num)
September 7
Apply