assignment is to write a program that helps an interactive user search for “near misses” of the form (x, y, z, n, k) in the formula x n + yn = zn , where x, y, z, n, k are positive integers, where 2< n <12, where 10 <= x <= k, and where 10 <= y <= k. When your program starts, it should ask the user for n (the power to use in the equation) and ask the user of k (which limits the range of x and y possibilities to test). For now I am not limiting k, except to say that it should be > 10. You may want to impose an upper limit on k if you find that your program is crashing due to overflowing integer variables, but don’t make it TOO small, or you will limit the kinds of near misses you can find. Your program should then look for “near misses” of the form x n + yn <> z n . A “near miss” is a RELATIVELY small difference between (x n + yn ) and z n for some integers x, y, and z. Your program should systematically search for x, y, and z combinations that are “almost right.” NOTE WELL: Fermat’s last theorem tells us that there should NOT be any x n + yn = z n combinations that are EXACTLY right for any n > 2. Also notice that although x and y are constrained above, z is NOT constrained directly. For each possible x,y combination, I suggest that you calculate (x n + yn ), and then look for whole numbers z and z + 1 that “bracket” (x n + yn ), so that zn < (x n + yn ) < (z+1)n . Find out which one (either zn or (z+1)n ) is closer to (x n + yn ), and determine the “miss” as the smallest of these two values: [(x n + yn ) - z n ] or [(z+1)n - (x n + yn )]. Then divide that miss by (x n + yn ) to obtain the RELATIVE size of the miss. Do this for all the possible combinations available, always keeping track of the smallest relative miss so far. Every time you find a new smallest relative miss, type out to the screen the current x, y, z, the actual miss (an integer), and the relative miss (a percentage or fraction). Make sure the interactive user can tell what the numbers mean as they are printed out; that is, label them well. When you have exhausted all the x, y, z triples possible, end the program. The screen should show the smallest possible miss as the last thing printed on the screen. Make sure that the IDE pauses so that the interactive user can carefully examine the output to the screen. PROGRAMMING TIP: Depending on which programming language you use, and what n and k the interactive user picks, you may have problems with variables overflowing. Please do your best to minimize those problems, but it is not a tragic thing if that happens for large n and k for programming languages that have trouble with big integers. It is better to hand in something simple that works, and on time, rather than handing in something fancy that is either late or doesn’t work. The best programs will work, be on time, be well documented (see below), and will make it clear to the interactive user what’s going on using screen output.
assignment is to write a program that helps an interactive user search for “near misses” of the form
(x, y, z, n, k) in the formula x
n + yn = zn
, where x, y, z, n, k are positive integers, where 2< n <12, where 10 <= x <= k, and
where 10 <= y <= k. When your program starts, it should ask the user for n (the power to use in the equation) and ask
the user of k (which limits the range of x and y possibilities to test). For now I am not limiting k, except to say that it
should be > 10. You may want to impose an upper limit on k if you find that your program is crashing due to overflowing
integer variables, but don’t make it TOO small, or you will limit the kinds of near misses you can find.
Your program should then look for “near misses” of the form x
n + yn <> z
n
. A “near miss” is a RELATIVELY small difference
between (x
n + yn
) and z
n
for some integers x, y, and z. Your program should systematically search for x, y, and z
combinations that are “almost right.” NOTE WELL: Fermat’s last theorem tells us that there should NOT be any x
n + yn =
z
n
combinations that are EXACTLY right for any n > 2. Also notice that although x and y are constrained above, z is NOT
constrained directly.
For each possible x,y combination, I suggest that you calculate (x
n + yn
), and then look for whole numbers z and z + 1 that
“bracket” (x
n + yn
), so that zn < (x
n + yn
) < (z+1)n
. Find out which one (either zn or (z+1)n
) is closer to (x
n + yn
), and
determine the “miss” as the smallest of these two values: [(x
n + yn
) - z
n
] or [(z+1)n
- (x
n + yn
)]. Then divide that miss by (x
n
+ yn
) to obtain the RELATIVE size of the miss. Do this for all the possible combinations available, always keeping track of
the smallest relative miss so far. Every time you find a new smallest relative miss, type out to the screen the current x, y,
z, the actual miss (an integer), and the relative miss (a percentage or fraction). Make sure the interactive user can tell
what the numbers mean as they are printed out; that is, label them well. When you have exhausted all the x, y, z triples
possible, end the program. The screen should show the smallest possible miss as the last thing printed on the screen.
Make sure that the IDE pauses so that the interactive user can carefully examine the output to the screen.
you may have problems with variables overflowing. Please do your best to minimize those problems, but it is not a tragic
thing if that happens for large n and k for programming languages that have trouble with big integers.
It is better to hand in something simple that works, and on time, rather than handing in something fancy that is either
late or doesn’t work. The best programs will work, be on time, be well documented (see below), and will make it clear to
the interactive user what’s going on using screen output.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images