python3 greatest common divisor of two numbers

It Shajiao number of convention?

  Divisor: It is a number that can be simultaneously both integer divisible integers. If at the same time is an integer divisor of several integers, the integer is called their "common divisor"; the biggest number Convention called the greatest common divisor

  For chestnut: common divisor of 12 and 18 have 12 and 18 1,2,3,6 because these can simultaneously be divisible. Six of the biggest common divisor

Program realization of ideas:

1  two numbers certainly not the greatest common divisor of two numbers is greater than the smaller of the number
 2  if a large number divides a smaller number, the smaller number that is the greatest common divisor
 3      namely: two integers modulo % b = a X
 . 4          If = X 0; b is the greatest common divisor of
 5  to identify the number of simultaneously divisible by two positive integer
 6 to print a maximum number of all simultaneously divisible by the greatest common divisor is the number of

Code implementation:

= Int number1 (INPUT ( " Please enter a positive integer: " )) 
Number2 = int (INPUT ( " Please enter the second positive integer: " ))
 IF number1> Number2: 
    Ten = number1 
    number1 = Number2 
    Number2 = Ten
 for I in Range (. 1 , Number1):
     IF Number2% Number1 == 0: 
        C = Number1
     elif (Number1 == 0% I) and (I Number2% == 0): 
        C = I
 Print( " Digital% s% s and the greatest common divisor is:% s " % (Number1, Number2, C))

Wherein the first if, primarily to the smaller value is fixed to the Number1, behind convenient value

The second row if the fourth order to achieve the above ideas

elif be able to find all the positive integers divisible by two numbers simultaneously

 

So be it, it is not difficult, just beginning to learn, have questions, comments, together with progress

Guess you like

Origin www.cnblogs.com/Zhan-W/p/11520066.html