Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

4 of 4
deleted 3 characters in body
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Python 2, (削除) 41 (削除ここまで) 40 bytes

n=k=j=input()
while~k<0:j-=1;k-=j>>n%j*n

Output is via exit code, so 0 is truthy and 1 is falsy.

Try it online!

How it works

After setting all of n, k, and j to the input from STDIN, we enter the while loop. Said loop will break as soon as -k - 1 = ~k ≥ 0, i.e., k ≤ -1 / k < 0.

In each iteration, we first decrement j to consider only proper divisors of n. If j is a divisor of n, n%j yields 0 and j >> n%j*n = j/20 = j gets subtracted from k. However, if j does not divide n, n%j is positive, so n%j*n is at least n > log2 j and j >> n%j*n = j / 2n%j*n = 0 is subtracted from k.

For abundant numbers, k will reach a negative value before or when j becomes 1, since the sum of n's proper divisors is strictly greater than n. In this case, we break out of the while loop and the program finishes normally.

However, if n is not abundant, j eventually reaches 0. In this case, n%j throws a ZeroDivisionError and the program exits with an error.

Dennis
  • 211.7k
  • 41
  • 380
  • 830

AltStyle によって変換されたページ (->オリジナル) /