AI Skill Report Card

Using Math Integer Operations

B-62·Sep 5, 2026·Source: Web
14 / 15
Python
import math # Greatest common divisor / least common multiple math.gcd(48, 18) # 6 math.lcm(4, 6) # 12 # Integer square root (floor of sqrt) math.isqrt(50) # 7 # Factorial math.factorial(5) # 120 # Combinatorics math.comb(5, 2) # 10 (combinations) math.perm(5, 2) # 20 (permutations) # Integer bit length (255).bit_length() # 8 (255).bit_count() # 8 (number of set bits)
Recommendation
This is a reference doc for well-known standard library functions rather than a methodology skill — it lacks a real workflow with decision points or non-obvious problem-solving guidance, which caps completeness.
10 / 15

Progress:

  • Identify whether the task needs exact integer math (avoid float rounding issues)
  • Choose the correct function: gcd/lcm for divisibility, isqrt for roots, factorial/comb/perm for counting
  • Validate input types — these functions require non-negative integers (raise ValueError on negatives where applicable)
  • Use built-in int methods (bit_length, bit_count) for binary-level analysis instead of manual bit-shifting loops
  • Test edge cases: zero, one, and large numbers (Python ints are arbitrary precision, so no overflow — but performance may degrade)
Recommendation
Examples are trivial function calls rather than realistic scenarios where choosing the right approach matters (e.g., a task combining multiple functions or a tricky edge case like gcd(0,0)).
13 / 20

Example 1: Input: Find the GCD and LCM of 24 and 36. Output:

Python
math.gcd(24, 36) # 12 math.lcm(24, 36) # 72

Example 2: Input: Compute the integer square root of 99 without floating-point error. Output:

Python
math.isqrt(99) # 9 (since 9*9=81 <= 99 < 100=10*10)

Example 3: Input: Count how many ways to choose 3 items from 7 (combinations), and how many ordered arrangements (permutations). Output:

Python
math.comb(7, 3) # 35 math.perm(7, 3) # 210

Example 4: Input: Determine the number of bits needed to represent 1023 in binary. Output:

Python
(1023).bit_length() # 10
Recommendation
Add a section on when NOT to use these (e.g., very large factorials causing performance issues, or when to fall back to numpy for vectorized integer math).
  • Prefer math.isqrt() over int(math.sqrt(n)) for exact results on large integers — floating-point sqrt loses precision beyond ~2^53.
  • Use math.gcd(*args) with multiple arguments to compute GCD across more than two numbers at once.
  • Use math.comb/math.perm instead of manually computing factorials and dividing — they're faster and avoid intermediate overflow-like slowdowns.
  • For bitwise integer inspection, prefer int.bit_length() and int.bit_count() over string conversion (bin()) or manual loops.
  • Remember Python integers have arbitrary precision — no need for overflow checks, but be mindful of performance with very large numbers (e.g., factorial(100000)).
  • Don't pass negative numbers to math.isqrt(), math.factorial(), math.comb(), or math.perm() — they raise ValueError.
  • Don't use math.sqrt(n) ** 2 == n to check perfect squares — use math.isqrt(n) ** 2 == n instead to avoid float precision errors.
  • Don't confuse math.comb(n, k) (order doesn't matter) with math.perm(n, k) (order matters).
  • Don't manually implement GCD/LCM with loops — the built-in math.gcd/math.lcm are optimized (C-implemented) and handle edge cases like zero correctly (gcd(0, 0) == 0).
  • Don't assume bit_length() counts set bits — it returns the number of bits needed to represent the number, not the population count (use bit_count() for that).
0
Grade B-AI Skill Framework
Scorecard
Criteria Breakdown
Quick Start
14/15
Workflow
10/15
Examples
13/20
Completeness
12/20
Format
15/15
Conciseness
14/15