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.

CodePudding user response:

reference 1st floor zjq9931 response:
p said minus the number cannot be more than the sum of p,
If there is a negative number?

Negative does not consider,

CodePudding user response:

references a wise man should know already take good karma, 4/f, response:
if minus is increasing fixed starting from 0, it is easy, try other ideas based on the modified.


My train of thought will trouble?
1) all of the first ascending numeral, take the first number as reference
2) starting from the second number in order to die the first number, deposited the remainder in a count variable, at the same time determine whether more than p
3) again after minus the number of all, the greatest common divisor of more Numbers,

CodePudding user response:

references a wise man should know already take good karma, 4/f, response:
if minus is increasing fixed starting from 0, it is easy, try other ideas based on the modified.


You try this set of data:
10 3
10 10 10 10 10 10 10 10 10 14
The output is 2
Instead of one, because you can not reduce, minus the number of 0, is less than the 3,

CodePudding user response:

10 8 9 10 10 10 10 10 10 14 how to print 2?

CodePudding user response:

Above has said if is assuming increasing from 0 up as an example,

CodePudding user response:

Want to or minus, also said the above, other ideas on the basis of this changes,

CodePudding user response:

references to the tenth floor wise men know already should good karma response:
want to or minus, also said the above, other ideas based on changes in this case,

Can you give me understand, thank you.

CodePudding user response:

Say so, if you don't want to get 1 has managed to continue falling circulation let P until 0, which can obtain the largest convention this can understand? According to this idea to modify the code can be realized,

CodePudding user response:

refer to 12th floor wise men know already should good karma response:
so, if you don't want to get 1 has managed to continue falling circulation let P until 0, which can obtain the largest convention this can understand? Click here to modify the code can be realized,

Can't understand, can express the again,

CodePudding user response:

In other words, if can't find the convention is greater than 1 and P values and decreases until you find, if any, of the convention is greater than 1 if you are not the only one,
  • Related