Skip to content

Latest commit

 

History

History
28 lines (15 loc) · 931 Bytes

abc234_a_weird_function.md

File metadata and controls

28 lines (15 loc) · 931 Bytes

Weird Function

Original problem · C++ solution

Try first

Define the given polynomial once and preserve the exact nesting of its calls.

Reasoning

Define the given polynomial once and preserve the exact nesting of its calls. Use 64-bit intermediates for squared values.

Cost

  • Time: O(1).
  • Extra space: O(1).

C++ takeaway

The types of operands control intermediate arithmetic. Read large values into long long before forming sums, products, or differences so the arithmetic itself uses 64 bits.

Watch for

Integer division truncates toward zero; floor and ceiling formulas need special care for negative values.

Explain it back

State the invariant without looking at the code. Give one input that breaks the most tempting incorrect approach, then add it to the tests.