write a program that inputs two positive integers, m and n, and calculates (m % 1,000,000,000),...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
write a program that inputs two positive integers, m and n, and calculates (m" % 1,000,000,000), that is, the remainder of dividing m" by 1,000,000,000. In other words, it prints the last nine digits of m". For example, if the input integers are 2 and 40, it calculates 240 % 1,000,000,000 1,099,511,627,776 % 1,000,000,000 = 511,627,776. Input and output: Your program should input two integers, m and n, between 1 and 1,000,000,000,000,000,000, and print the value of (m" % 1,000,000,000). Screen shot: Command Prompt C:\>java Exercise4 Enter base: 2 Enter exponent: 40 2 40 % 1000000000 = = 511627776 C:\>java Exercise4 Enter base: 2 Enter exponent: 100000⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀00 2^1000000000000000000 % 1000000000 = 787109376 030 000 300 X C:\> Hint: The "brute-force" approach of first calculating m" by an n-iteration loop and then applying the % 1,000,000,000" operation to the result does not work. First, for large values of n, the value of m" may be far too large for the computer memory, even if it is declared as "BigDecimal". Second, an n-iteration loop may take impractically long time. write a program that inputs two positive integers, m and n, and calculates (m" % 1,000,000,000), that is, the remainder of dividing m" by 1,000,000,000. In other words, it prints the last nine digits of m". For example, if the input integers are 2 and 40, it calculates 240 % 1,000,000,000 1,099,511,627,776 % 1,000,000,000 = 511,627,776. Input and output: Your program should input two integers, m and n, between 1 and 1,000,000,000,000,000,000, and print the value of (m" % 1,000,000,000). Screen shot: Command Prompt C:\>java Exercise4 Enter base: 2 Enter exponent: 40 2 40 % 1000000000 = = 511627776 C:\>java Exercise4 Enter base: 2 Enter exponent: 100000⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀00 2^1000000000000000000 % 1000000000 = 787109376 030 000 300 X C:\> Hint: The "brute-force" approach of first calculating m" by an n-iteration loop and then applying the % 1,000,000,000" operation to the result does not work. First, for large values of n, the value of m" may be far too large for the computer memory, even if it is declared as "BigDecimal". Second, an n-iteration loop may take impractically long time.
Expert Answer:
Answer rating: 100% (QA)
To calculate mn 1000000000 efficiently without running into memory or time issues for the large values of n modular exponentiation can be used Java Pr... View the full answer
Related Book For
Elementary Principles of Chemical Processes
ISBN: 978-0471720638
3rd Edition
Authors: Richard M. Felder, Ronald W. Rousseau
Posted Date:
Students also viewed these programming questions
-
If a pure discount three-year bond sells for $782 and a pure discount four-year bond sells for $733, what is the expected 12-month interest rate in three years time? Both have a face value of $1000....
-
At the end of 2011, Searcy Corp. has accounts receivable of $600,000 and an allowance for doubtful accounts of $36,000. On January 24, 2012, Searcy learns that its $8,000 receivable from Hutley Inc....
-
Which of the following best describes the meaning of 'Purchases'? (A) Items bought (B) Goods bought on time (C) Goods bought for resale (D) Goods paid for
-
\(19.8 \sqrt{12}-6.1 \sqrt{3}\) Perform the arithmetic operations without a calculator, if possible. If it is not possible, state why.
-
Lindas Boards sells a snowboard, Xpert,that is popular with snowboard enthusiasts. Information relating to Lindas purchases of Xpert snowboards during September is shown below. During the same month,...
-
A father is planning a savings program to put his daughterthrough university. His daughter is now 13-year-old. She plans toenroll at the university in 5 years, and it should take her 4 yearsto comp 2...
-
The 2018 balance sheets and income statement for Netflix Inc. follow. Refer to these financial statements to answer the requirements. NETFLIX INC. Consolidated Statement of Earnings For Year Ended...
-
**Suppose that in January 2006 Kenneth Cole Productions had EPS of $1.65 and a book value of equity of $12.05 per share. Use the multiples approach to estimate? KCP's value based on the data from c...
-
What characteristics can be considered by the auditor to assess the appropriateness of audit evidence? Define these characteristics and illustrate each with an example.
-
What is an audit program? How does the auditor compose the audit program?
-
How does a continuous system differ from a discrete system in the nature of its equation of motion?
-
Identify and indicate the major components of each phase of an auditor's consideration of internal control.
-
True or False. Continuous systems are the same as distributed systems.
-
For the following project, compute an EAA: Project A requires you an upfront payment of $212872 and yearly payments of $51728 for 12 years. Your cost of capital is 4.59%
-
Smthe Co. makes furniture. The following data are taken from its production plans for the year. Required: 1. Determine the hazardous waste disposal cost per unit for chairs and for tables if costs...
-
Two hundred kilograms per hour of an aqueous solution containing 20.0mole% sodium acetate (NaC2H3O2) enters an evaporative crystallizer at 60C. When the solution is exposed to the low pressure in the...
-
A mixture of methane, ethane, and argon at 25C is burned with excess air in a power plant boiler. The hydrocarbons in the fuel are completely consumed. The following variable definitions will be used...
-
Calculate the total mass of chlorine (kg) in the chlorine absorber tank, assuming ideal gas behavior in the head space. (Suggestion: Take as a basis of calculation a specified mass of slurry,...
-
Question: Cruise.com operated a Web site selling cruise vacations. It sent unsolicited e-mail advertisements-dubbed "E-deals"-to prospective customers. Eleven of these "E-deals" went to...
-
Question: Jerry Falwell was a nationally known Baptist minister. You can read about him on falwell.com. You can read about his views on homosexuality at fallwell.com-a site critical of his views....
-
Question: Timothy Vemor bought used (but original) versions of AutoCAD software at garage and office sales. Each time he tried to sell them on eBay, AutoDesk (the company that produced the software)...
Study smarter with the SolutionInn App