a, b, and x are positive integers such that
sqrt(a) + sqrt(b) = sqrt(x)
How many possible values of x less than or equal to 1000 are there?
(In reply to
The correct(?) solution by John Reid)
The error in my program is the line
IF b < a THEN EXIT DO
The first value of x missed was 24, for which, when this line was encountered, b was 5.9999999999999 and a was 6. If precision were perfect, both would have been 6 and b would not have been considered less than a. The corrected program has
IF b - a < -.0000001# THEN EXIT DO
and produces statistics:
392 961 30 240
showing 392 values of x from 961 possible sums.
|
Posted by Charlie
on 2005-05-06 13:47:18 |