Question: please write this code in java language by using while-loops, and do not use flag!! Because we did not learn the flag so far! thank


please write this code in java language by using while-loops, and do not use flag!! Because we did not learn the flag so far! thank you!!!
The Coding Idea The prime factorization of an integer N can be found dynamically using an algorithm that attempts to find its prime factors by generating candidate factors in the increasing order of their values. Each time a candidate factor is found to divide the number without remainder, the candidate factor is indeed a factor, so the number is reduced with the division by the factor that hast just been found. This division is repeated until the number is no more divisible by the factor. After dividing the number with the found factor as many as it is possible, if the number has been reduced to 1, all the prime factors have been found, so the prime factorization has been completed. Otherwise, the value of the candidate factor should be increased by 1 The idea described in the above can be implemented as follows: Step 1 Declare two long variables, theQuotient and theDivisor. The initial value of theQuotient is the input number, N. The initial value of theDivisor is 2 Step 2 While theQuotient > 1, repeat the following: Step 2a If theDivisor divides thequotient without remainder, as long as this property holds, reduce theQuotient by dividing it by theDivisor Step 2b Add 1 to theDivisor Since the value of theDivisor starts from 2 and increased by 1 each time, it is guaranteed that when theDivisor divides theQuotient without remainder, theDivisor is a prime number. Why? Intuitively, this is because if the present value, p, of theDivisor is not a prime number, it has a prime factor, q, that is smaller that p, and so the algorithm would have found, when the value of
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
