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....
-
Is Wal Kings job, complex and stratospheric as it is compared to most others, indicative of what managers can expect in their roles? What roles do you perceive, relative to those discussed in part 1...
-
Vista Company manufactures electronic equipment. In 2015 it purchased from an outside supplier the special switches used in each of its products. The supplier charged Vista $2 per switch. As an...
-
What is the optimal distance a proximity probe should be mounted from the shaft of interest?
-
Stallone Company is considering two possible investments, each of which requires an initial investment of $36,000. Investment A will provide a cash flow of $4,000 at the end of each year for 20...
-
Four grams of musk oil are required for each bottle of Mink Caress, a popular perfume made by a company in western Siberia. The cost of the musk oil is $1.80 per gram. Budgeted quarterly production...
-
Greenville has provided the following information from its General Fund Revenues and Appropriations/ Expenditure/Encumbrances subsidiary ledgers for the fiscal year ended. Assume the beginning fund...
-
Ivan bought books and ice cream sodas. Books are on sale at $5 each while ice cream sodas are currently sold at $12 each. If Ivan spent $82 and only got 8 items, how many books and ice cream sodas...
-
Laguna Manufacturing is considering replacing a piece of equipment with a newer, more efficient model. The old equipment was purchased several years ago for $112,500 and has annual operating costs of...
-
Patient has outstanding balance $25 for service 12/31/23 only. please see message below. Hello, I received a letter showing an outstanding balance for two of Nilou's visits; 1. 12/31/23 Isabel...
-
P2a. Various financial data for the past two years follow. Calculate the productivity ratios and enter the % change (round to one decimal place) from last year to this year. Output: Inputs: Volume (#...
-
Please use this assignment to submit the various Research Essay First Draft revisions that we discussed in class. Choose FOUR sections that need improvement (the Introduction, a Body Paragraph, a...
-
What are the 3 questions (in order of sequence) to analyze business transactions? Explain.
-
Exercise: Solve the following system of linear congruences x = 2 mod 6, x= 1 mod 5, r = 3 mod 7.
-
The value of a share of common stock depends on the cash flows it is expected to provide, and those flows consist of the dividends the investor receives each year while holding the stock and the...
-
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,...
-
A batch distillation facility has a bank of columns of Type 1 and another bank of Type 2. Type 1 columns are available for processing \(6,000 \mathrm{hr} /\) week, and Type 2 columns are available...
-
During the 2002 Winter Olympics in Salt Lake City, Utah, a local microbrewery received a rush order for 100 gallons of beer containing at least 4.0 volume \(\%\) alcohol. Although no \(4 \%\) beer...
-
Willy Wonka has engaged your consultation services to assist in the recipe formulation of a new brand of chocolate bar, weighing \(100 \mathrm{~g}\), which he plans to name "Super-choc." Each...
Study smarter with the SolutionInn App