Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

write a program that inputs two positive integers, m and n, and calculates (m

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: 10000000 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.

Step by Step Solution

3.41 Rating (148 Votes )

There are 3 Steps involved in it

Step: 1

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Elementary Principles of Chemical Processes

Authors: Richard M. Felder, Ronald W. Rousseau

3rd Edition

978-0471687573, 9788126515820, 978-0-471-4152, 0471720631, 047168757X, 8126515821, 978-0471720638

More Books

Students also viewed these Programming questions

Question

How do we expect this issue to be resolved?? p-9687

Answered: 1 week ago

Question

Write a paper about medication error system 2016.

Answered: 1 week ago