Perfect Number
Real-world version: Balanced Batch SizeThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def check_perfect_number(num: int) -> bool:public boolean checkPerfectNumber(int num)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's