Python Programming: An Introduction to Computer Science
Python Programming: An Introduction to Computer Science
3rd Edition
ISBN: 9781590282779
Author: John Zelle
Publisher: Franklin Beedle & Associates
bartleby

Videos

Question
Book Icon
Chapter 8, Problem 8PE
Program Plan Intro

Greatest Common Divisor

Program Plan:

  • Declare a main function. Inside the main function,
    • Get the two numbers from the user.
    • In the “try’ block,
      • Check “m” value is less than “n” value.
        • Swap the values.
      • Check “m” value is not equal to 0.
        • Set the value
        • Calculate the “m” value
        • Again, set the value.
      • Display the result.
    • In exception block, display the error message.
  • Call the main function.

Blurred answer
Students have asked these similar questions
A formula for finding the greatest common divisor (GCD) of two numbers was formulated by the mathematician Euclid around 300 BCE. The GCD of two numbers is the largest number that will divide into both numbers without any remainder. For example, the GCD of 12 and 16 is 4, the GCD of 18 and 12 is 6.The basic algorithm is as follows:Assume we are computing the GCD of two integers x and y. Follow the steps below:1. Replace the larger of x and y with the remainder after (integer) dividing the larger number by the smaller one.2. If x or y is zero, stop. The answer is the nonzero value.3 If neither x nor y is zero, go back to step 1.Here is an example listing the successive values of x and y:   x          y135         20       %(135 / 20) = 15 15         20       %(20 / 15) = 5 15          5       %(15 / 5) = 0      0          5       GCD = 5       Write a recursive method that finds the GCD of two numbers using Euclid’s algorithm. public class Arithmetic{   public static int gcd(int a, int…
Correct answer will be upvoted else downvoted.   number is called 2050-number if it is 2050, 20500, ..., (2050⋅10k for integer k≥0).   Given a number n, you are asked to represent n as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-numbers required for that.   Input The first line contains a single integer T (1≤T≤1000) denoting the number of test cases.   The only line of each test case contains a single integer n (1≤n≤1018) denoting the number to be represented.   Output For each test case, output the minimum number of 2050-numbers in one line.   If n cannot be represented as the sum of 2050-numbers, output −1 instead.
Start with a pile of n stones and successively split a pile into two smaller piles until each pile has only one Each time a split happens, multiply the number of stones in each of the two smaller piles. (For example, if a pile has 15 stones and you split it into a pile of 7 and another pile of 8 stones, multiply 7 and 8.)  The goal of this problem is to show that no matter how the  pile of n  stones are split, the sum of the products computed at each split is equal to n(n - 1)/2. Using strong mathematical induction, prove that no matter how the pile of n stones are split, the sum of the products computed at each split is equal to n(n - 1)/2.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY