slovo/benchmarks/math-loop/python/math_loop.py
2026-05-22 08:38:43 +02:00

34 lines
652 B
Python

LOOP_COUNT = 1_000_000
EXPECTED_CHECKSUM = 5_000_001
def math_loop(limit: int) -> int:
i = 0
acc = 1
while i < limit:
acc = acc + ((i + 3) * 2)
acc = acc - 1_000_000_000 if acc > 1_000_000_000 else acc
i += 1
return acc
def configured_loop_count() -> int:
try:
value = int(input().strip())
except (EOFError, ValueError):
return LOOP_COUNT
return value if value > 0 else LOOP_COUNT
def main() -> int:
result = math_loop(configured_loop_count())
print(result)
return 0 if result == EXPECTED_CHECKSUM else 1
if __name__ == "__main__":
raise SystemExit(main())