1. Problem Description The greatest common divisor gcd (a, b) between two positive integers a and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Problem Description The greatest common divisor gcd (a, b) between two positive integers a and b is defined as the largest positive integer that divides both a and b without a remainder. GCD is a very powerful tool in modern cryptography, and when the target integers to be calculated are small (less than 108), GCD can be calculated in a few seconds with a naïve method. However, the numbers in modern cryptography requires at least 512 digits to prevent attackers from using a brute-force method to derive the secret key. This required number is too large for the naïve methods to calculate GCD in a reasonable time and the numbers exceeds the limit of even long long in the C language. In this problem, you will need to calculate the GCD of two big integers efficiently. 2. Input Format One line containing two integers, a and b, where 0 < a, b < 10256 3. Output Format An integer representing gcd (a, b) with a single end-of-line (endl). 4. Sample Input/Output Sample Input 1 20230925 52903202 Sample Output 1 11 Sample Input 2 111111222222333333444444555555 666666777777888888999999 Sample Output 2 333333 1. Your program must be written in C/C++ language and can be compiled Linux platform. on the To deal with the big integers, we need a "data structure", such as an integer array in C to represent larger values. For instance, you can use an integer array where each element represents one (decimal) digit, like representing 202309 by the following code snippet. vector<int> digits = {9, 0, 3, 2, 0, 2); It is not required to use the representation above, though. You can use any representation that facilitates your implementation. Algorithm: Binary Algorithm for Greatest Common Divisor Input: Two positive integers a and b. Output: A positive integer ans representing greatest common divisor of a and b. nmin(a, b), m←max(a, b), ans 1 while n 0 and m #0 do if n is even and m is even then 1 ans ans x 2, n + n/2,m+m/2 else if n is even then In n+ n/2 else if m is even then m+m/2 end if n > m then swap(n, m) m← (m-n) end return n x ans 1. Problem Description The greatest common divisor gcd (a, b) between two positive integers a and b is defined as the largest positive integer that divides both a and b without a remainder. GCD is a very powerful tool in modern cryptography, and when the target integers to be calculated are small (less than 108), GCD can be calculated in a few seconds with a naïve method. However, the numbers in modern cryptography requires at least 512 digits to prevent attackers from using a brute-force method to derive the secret key. This required number is too large for the naïve methods to calculate GCD in a reasonable time and the numbers exceeds the limit of even long long in the C language. In this problem, you will need to calculate the GCD of two big integers efficiently. 2. Input Format One line containing two integers, a and b, where 0 < a, b < 10256 3. Output Format An integer representing gcd (a, b) with a single end-of-line (endl). 4. Sample Input/Output Sample Input 1 20230925 52903202 Sample Output 1 11 Sample Input 2 111111222222333333444444555555 666666777777888888999999 Sample Output 2 333333 1. Your program must be written in C/C++ language and can be compiled Linux platform. on the To deal with the big integers, we need a "data structure", such as an integer array in C to represent larger values. For instance, you can use an integer array where each element represents one (decimal) digit, like representing 202309 by the following code snippet. vector<int> digits = {9, 0, 3, 2, 0, 2); It is not required to use the representation above, though. You can use any representation that facilitates your implementation. Algorithm: Binary Algorithm for Greatest Common Divisor Input: Two positive integers a and b. Output: A positive integer ans representing greatest common divisor of a and b. nmin(a, b), m←max(a, b), ans 1 while n 0 and m #0 do if n is even and m is even then 1 ans ans x 2, n + n/2,m+m/2 else if n is even then In n+ n/2 else if m is even then m+m/2 end if n > m then swap(n, m) m← (m-n) end return n x ans
Expert Answer:
Answer rating: 100% (QA)
For calculating the greatest common divisor GCD of two large integers efficiently in C on a Linux sy... View the full answer
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Consider the Cobb-Douglas production function f(x, y) = 300x0.85, 0.15 When x = 4000 and y = 800, find the following. (Round your answers to two decimal places.) (a) the marginal productivity of...
-
Liberty Ventures Inc. reported a $320,000 profit in 2020 and declared preferred dividends of $20,000. The following changes in common shares outstanding occurred during the year: Jan 1 100,000 common...
-
Joe and Jessie are married and have one dependent child, Lizzie. Lizzie is currently in college at State University. Joe works as a design engineer for a manufacturing firm while Jessie runs a craft...
-
The following table lists the total revenue for each of a few selected companies for the year 2014 Company Revenue for Fiscal Year 2014 (millions of dollars) Walmart...
-
True or False: If \(E R R>M A R R\), then MIRR \(>\) MARR.
-
The owner of a ski apparel store in Winter Park, CO, must decide in July how many ski jackets to order for the following ski season. Each ski jacket costs $54 each and can be sold during the ski...
-
What are some ways to determine which database management system will work best for a given project? What are some best practices or industry-accepted criteria for matching a given database...
-
Effective January 1, 1970, Chrysler Corporation adopted the FIFO method for inventories previously valued by the LIFO method. The 1970 annual report stated, This . makes the financial statements with...
-
An electric wire carries a dc current of 40 A vertically upward. (a) What is the magnetic field due to this current at a point P, 10 cm due north of the wire ? (b) What is its direction?
-
(WAN) T1 circuit transmits data via a frame of 193 bit shown as the below figure. (1) Please calculate the T1's data rate? (2) Please calculate the data rate of transmitting the Frame Bit S? Frame...
-
On July 31, 2021, Hummbug Corporation issued $100,000, 5%, 20-year bonds for $113,678, when the market interest rate was 4%. The bonds pay semi-annual interest on July 31 and January 31. Hummbug uses...
-
For a gauge pressure at A of -10.89 kPa, find the specific gravity of the gauge liquid L in the figure below. air 3.429m 3.2m +A 3.048m 2.743m Liquid L S.G.=1.6
-
Jesus, a soft-spoken employee of DCS Sanitation Management, Inc., the company that IBP uses in many of its plants, told me that every night on the job he gets terrible headaches. "You feel it in your...
-
The process varies depending on the group being surveyed, such as family members, communities, or select groups involved in specific markets like insurance or healthcare. They also use existing...
-
1. Your boss confides in you that one of your highly successful coworkers has been padding his expense account by billing for personal items. This action violates a company policy, which notes that...
-
Ann hires a nanny to watch her two children while she works at a local hospital. She pays the 19 year-old nanny $125 per week for 48 weeks during the current year. a. What is the employers portion of...
-
The recursive Towers of Hanoi. Write a animated solution to the Towers of Hanoi that shows the disks moving between pegs. Allow the user to enter the number of disks.
-
Heres a peek ahead. In this chapter, you learned about integers and the type int. Java can also represent floating-point numbers that contain decimal points, such as 3.14159. Write an application...
-
Many programs written with inheritance could be written with composition instead, and vice versa. Rewrite class BasePlus-CommissionEmployee (Fig. 9.11) of the...
-
Why do you and your business need to be able to communicate well?
-
What are the basic criteria for effective messages?
-
What are the questions for analyzing a business communication situation?
Study smarter with the SolutionInn App