Question: Write a function named minDistance that returns the smallest distance between two nontrivial factors of a number. For example, consider 6 3 . Its non

Write a function named minDistance that returns the smallest distance between two nontrivial factors of a number. For example, consider 63. Its non-trivialfactors are 3,7,9 and 21.
Thus minDistance(63) would return 2 because the smallest distance between any two non-trivial
factors is 2(9-7=2). As another example, minDistance (25) would return 0 because 25 has
only one non-trivial factor: 5. Thus the smallest distance between any two non-trivial factors is 0(5-5=
0). Note that minDistance(11) would return -1 since 11 has no non-trivial factors.
The function signature is
int minDistance(int n)
N.B You should only answer in Java

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!