Home > Back-end > Such an algorithm, how to solve? Please give an algorithm.
Such an algorithm, how to solve? Please give an algorithm.
Time:05-18
Several number to each number minus a certain numerical value, can make the number it is the greatest common divisor of several of the biggest, such as: Input and p. m. M: said m number, minus the number cannot be more than the sum of p, p said Finally this the greatest common divisor of m number as far as possible big, For example: Enter 6, 10 5 6 7 8 9 10 Output: 5 Description: M=6, p=10 6 number respectively is: 5 6 7 8 9 10 The second number minus 1, the second number minus 2, 3, the third number minus the fourth number minus 4. Minus the value of 1 + 2 + 3 + 4 & lt;=p (10) the value, So: After subtracting became: The greatest common divisor of 5,5,5,5,5,10, these 6 number 5.
CodePudding user response:
P said minus the number of no more than the sum of p, If there is a negative number?
CodePudding user response:
Greatest common divisor, affirmation and the smallest number equal to or less than the minimum number, then more than with the smallest number as common divisor to want to add
CodePudding user response:
If it does not meet the minimum number minus one, cycle calculation
CodePudding user response:
If increasing minus is fixed starting from 0, it is easy, try other ideas on the basis of the modified.