Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
expand_more
expand_more
format_list_bulleted
Question
Chapter 8, Problem 8PE
Program Plan Intro
Greatest Common Divisor
- 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.
- Check “m” value is less than “n” value.
- In exception block, display the error message.
- Call the main function.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
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.
Correct answer will be upvoted else downvoted. Computer science.
You are given an integer n. Check if n has an odd divisor, more noteworthy than one (does there exist such a number x (x>1) that n is separable by x and x is odd).
For instance, assuming n=6, there is x=3. Assuming n=4, such a number doesn't exist.
Input
The primary line contains one integer t (1≤t≤104) — the number of experiments. Then, at that point, t experiments follow.
Each experiment contains one integer n (2≤n≤1014).
If it's not too much trouble, note, that the input for some experiments will not squeeze into 32-cycle integer type, so you should use no less than 64-digit integer type in your programming language.
Output
For each experiment, output on a different line:
"Indeed" if n has an odd divisor, more noteworthy than one;
"NO" in any case.
You can output "YES" and "NO" regardless (for instance, the strings yEs, indeed, Yes and YES will be perceived as certain).
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.
Chapter 8 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
Ch. 8 - Prob. 1TFCh. 8 - Prob. 2TFCh. 8 - Prob. 3TFCh. 8 - Prob. 4TFCh. 8 - Prob. 5TFCh. 8 - Prob. 6TFCh. 8 - Prob. 7TFCh. 8 - Prob. 8TFCh. 8 - Prob. 9TFCh. 8 - Prob. 10TF
Ch. 8 - Prob. 1MCCh. 8 - Prob. 2MCCh. 8 - Prob. 3MCCh. 8 - Prob. 4MCCh. 8 - Prob. 5MCCh. 8 - Prob. 6MCCh. 8 - Prob. 7MCCh. 8 - Prob. 8MCCh. 8 - Prob. 9MCCh. 8 - Prob. 10MCCh. 8 - Prob. 2DCh. 8 - Prob. 3DCh. 8 - Prob. 1PECh. 8 - Prob. 2PECh. 8 - Prob. 3PECh. 8 - Prob. 4PECh. 8 - Prob. 5PECh. 8 - Prob. 6PECh. 8 - Prob. 7PECh. 8 - Prob. 8PECh. 8 - Prob. 9PECh. 8 - Prob. 10PECh. 8 - Prob. 11PECh. 8 - Prob. 12PECh. 8 - Prob. 13PE
Knowledge Booster
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
- 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…arrow_forwardWrite a program that prints an mxn matrix whose dimensions are specified by the user. Let the matrix values be random variables. You must use it within the repetition cycle. Example format: Enter dimension of matrix mxn: 2 4 The 2x4 matrix is : 1 2 3 4 5 6 7 8arrow_forwardIn this exercise, we will write a program to find the sum of all numbers between any two seeded randomly generated numbers, inclusively, where the randomly generated numbers are also included in the sum. For example, if the randomly generated integers are 15 and 25, you need to sum all odd numbers from 15 to 25, and 15 and 25 are also included in the sum. Note that the random number generated may be even, so you should NOT include that number in your sum. In this program, you will: • Generate the first random integer between 10 and 30, inclusive. • Generate a second random integer between 40 and 60, inclusive. • Inside a while loop, accumulate the sum of all numbers between the two random numbers generated, being sure to include the two random numbers in the sum. • Display the two random numbers as well as the sum on the screen with suitable messages. Using C++ languagearrow_forward
- In this exercise, we will write a program to find the sum of all numbers between any two seeded randomly generated numbers, inclusively, where the randomly generated numbers are also included in the sum. For example, if the randomly generated integers are 15 and 25, you need to sum all odd numbers from 15 to 25, and 15 and 25 are also included in the sum. Note that the random number generated may be even, so you should NOT include that number in your sum. In this program, you will: • Generate the first random integer between 10 and 30, inclusive. • Generate a second random integer between 40 and 60, inclusive. • Inside a while loop, accumulate the sum of all numbers between the two random numbers generated, being sure to include the two random numbers in the sum. • Display the two random numbers as well as the sum on the screen with suitable messages.arrow_forwardWrite a program that uses random function to randomly generate 6 integers between 0 and 99 with 0 and 99 included. Save them in a Bag. Ask a user to make a guess. If the user’s guess is one of the numbers in the Bag, then give user 10 points and remove the number from the Bag. Allow the user to make 10 attempts. Each time give user 10 points if the number user guess is in the Bag. If the Bag is getting emptied before the user reach 10 attempts, then give user an additional 200 points and terminate the program (Game is over!). If the Bag is not empty after the user use up all 10 attempts, then display the user’s score and terminate the program (Game is over!). **Note** I am having trouble figuring out the 10 attempts and random numbers part of the program.arrow_forwardIn computer science, the analysis of algorithms is the process of finding the computational complexity of algorithms – the amount of time, storage, or other resources needed to execute them. Discuss the algorithm for recursion method that takes in a string and returns a reversed copy of the string and also Write a Program using the same algorithm for recursion method. The only inbuilt string function you are allowed to use is string concatenation. Ex. Input text = "Pyhton", Output > "nothyP"arrow_forward
- Write a program that reads two matrices of integers. It then generates the sum and difference of the two matrices. The sum of the two matrices of the same size is a matrix with elements that are the sums of the corresponding elements of the two given matrices. Addition is not defined for matrices of different sizes. If A and B are matrices of the same size, then we define subtraction as follows: A – B = A + (-B). Thus, to subtract matrix B from matrix A, we simply subtract corresponding elements. Note: Use array functionarrow_forwardLet A = {a, b, c} and B = {u, v}. Write a. A × B b. B × Aarrow_forwardGiven a square matrix with the elements 0 or 1, write a program tofind a maximum square submatrix whose elements are all 1s. Your programshouldprompt the user to enter the number of rows in the matrix. The program then displaysthe location of the first element in the maximum square submatrix and thenumber of rows in the submatrix. Here is a sample run: Enter the number of rows in the matrix: 5 ↵EnterEnter the matrix row by row:1 0 1 0 1 ↵Enter1 1 1 0 1 ↵Enter1 0 1 1 1 ↵Enter1 0 1 1 1 ↵Enter1 0 1 1 1 ↵EnterThe maximum square submatrix is at (2, 2) with size 3 Your program should implement and use the following method to find the maximumsquare submatrix:public static int[] findLargestBlock(int[][] m)The return value is an array that consists of three values. The first two values arethe row and column indices for the first element in the submatrix, and the thirdvalue is the number of the rows in the submatrix.arrow_forward
- Using Matlab. Monte Carlo methods are a class of computational methods that rely on repeated random sampling to compute their results. In this problem, you will use the Monte Carlo method to estimate the temperature at an arbitrary point in a uniform solid. Specifically, we will consider the solid object shown below. The temperatures of all surfaces are 500 des F with the exception of the two shaded surfaces, which are at 0 deg F. Inputs to the program should be: 1. The number of random walkers. 2. The (x,,2) coordinates of the point at which the temperature is to be estimated. 3. Plot interval (eg., you may want 1,000,000 random walkers in the simulation but may want to plot after every 10,000). Output from the program should be: 1. A graph of the estimated temperature, plotted according to the plot interval 2. Numerical value of the estimated temperature. USING MATLABarrow_forwardThe Fibonacci sequence is a famous sequence in mathematics. The first element in the sequence is 0 and the second element is 1. The nth element is defined as Fn = Fn-1 + Fn-2- Implement the fib function, which takes an integer n and returns the n th Fibonacci number. Use a while loop in your solution. def fib(n): """Returns the nth Fibonacci number. >>> fib (0) 0 >>> fib (1) 1 >>> fib(2) 1 >>> fib(3) 2 >>> fib(4) 3 >>> fib(5) 5 >>> fib(6) 8 >>> fib (100) 354224848179261915075 "*** YOUR CODE HERE ***"arrow_forwardWrite a program that computes and displays the five set of products of each three random numbers between 1 and 20 using only for loops (Don’t use Arrays). Here is a sample run: The Product 1: of 2, 10, 8 is 180 The Product 2: of 11, 3, 20 is 660 The Product 3: of 5, 12, 8 is 480 The Product 4: of 3, 5, 7 is 105 The Product 5: of 12, 11, 18 is 2376arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
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