Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 41s1 days 16 hours 1 minutes 41 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 41s1 days 16 hours 1 minutes 41 seconds.

Sign in to watch this lesson
Advanced - Number Theory · 3:54
The equation a·x + b·y = c has integer solutions exactly when g = gcd(a, b) divides c, and one solution comes from extended Euclid scaled by c/g. All solutions lie evenly spaced on a line, x = x0 + k·b/g and y = y0 − k·a/g, so counting them inside limits means intersecting two ranges of k with floor division, and any linear cost is optimal at an end of that range.