Examples: Input: 122 Output: 1 Explanation: Four good numbers of length 2 exist - 11, 12, 21, and 22. Of those four, only 11 is superb because its digits sum up to 2. Input: 58 997690 Output: 21735480 Input: 782 Output: */

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please do this on JAVA PROGRAMMING

 

Examples:
Input:
122
Output:
1
Explanation:
Four good numbers of length 2 exist - 11, 12, 21, and 22. Of those four,
only 11 is superb because its digits sum up to 2.
Input:
58 997690
Output:
21735480
Input:
782
Output:
* /
Transcribed Image Text:Examples: Input: 122 Output: 1 Explanation: Four good numbers of length 2 exist - 11, 12, 21, and 22. Of those four, only 11 is superb because its digits sum up to 2. Input: 58 997690 Output: 21735480 Input: 782 Output: * /
Holy Numbers
/*
Winnica loves numbers. She considers the digits a and b to be holy, and
thus considers a number good if it only contains digits a and b. Winnica
considers a good number to be superb if the sum of its digits is a good
number. Help Winnica determine how many superb numbers exist of length n.
In order to prevent overflow when calculating your answer, print your
answer modulo 1000000007.
Why 1000000007?
Consider the sequence
10, 20, 30, 40, 50, 60, 70, 80, 90, 100, ... modulo 8 =
2, 4, 6, 0, 2, 4, 6, 0, 2, 4 ... repeating values.
%3D
Now consider
10, 20, 30, 40, 50, 60, 70, 80, 90, 100,... modulo 7 (prime) =
3, 6, 2, 5, 1, 4, 0, 3, 6, 2,...no repeats in first 7 terms.
The best number to prevent modulo repeats, or overlaps, is a prime number
greater than the number of terms. When concerned with integer overflow, the
best choice is the largest prime <= the largest integer which can be stored
in 32 bits, which is 2^31 - 1 (the 32nd bit is used for sign). As it turns
out, 2^31 - 1 = 2,147,483,647 =1111111
2.147483647 x 10^9 is itself prime.
111111111111111111111 base 2 =
%3D
1,000,000,007 = 10^9 + 7, the first 10-digit prime number, is however easier
to write and for our purposes will do the job. The true number theorist will
pursue the reason why prime numbers are so useful in modular arithetic more
deeply. See, e.g.
https://theoryofprogramming.wordpress.com/2014/12/24/modular-arithmetic-
properties/
Incidentally, 1000000007 is not only a naughty prime, meaning all except the
end digits = 0, but also an extremely naughty prime, meaning the number of
zeros = the sum of the end digits. It is also an emirp (prime spelled backwards),
meaning it gives you a different prime when its digits are reversed.
%3D
Input:
The first line contains three integers a, b, and n
(1< a<b< 9,1sn< 10^6).
Output:
Print the answer modulo 1000000007 (10^9 + 7).
Transcribed Image Text:Holy Numbers /* Winnica loves numbers. She considers the digits a and b to be holy, and thus considers a number good if it only contains digits a and b. Winnica considers a good number to be superb if the sum of its digits is a good number. Help Winnica determine how many superb numbers exist of length n. In order to prevent overflow when calculating your answer, print your answer modulo 1000000007. Why 1000000007? Consider the sequence 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, ... modulo 8 = 2, 4, 6, 0, 2, 4, 6, 0, 2, 4 ... repeating values. %3D Now consider 10, 20, 30, 40, 50, 60, 70, 80, 90, 100,... modulo 7 (prime) = 3, 6, 2, 5, 1, 4, 0, 3, 6, 2,...no repeats in first 7 terms. The best number to prevent modulo repeats, or overlaps, is a prime number greater than the number of terms. When concerned with integer overflow, the best choice is the largest prime <= the largest integer which can be stored in 32 bits, which is 2^31 - 1 (the 32nd bit is used for sign). As it turns out, 2^31 - 1 = 2,147,483,647 =1111111 2.147483647 x 10^9 is itself prime. 111111111111111111111 base 2 = %3D 1,000,000,007 = 10^9 + 7, the first 10-digit prime number, is however easier to write and for our purposes will do the job. The true number theorist will pursue the reason why prime numbers are so useful in modular arithetic more deeply. See, e.g. https://theoryofprogramming.wordpress.com/2014/12/24/modular-arithmetic- properties/ Incidentally, 1000000007 is not only a naughty prime, meaning all except the end digits = 0, but also an extremely naughty prime, meaning the number of zeros = the sum of the end digits. It is also an emirp (prime spelled backwards), meaning it gives you a different prime when its digits are reversed. %3D Input: The first line contains three integers a, b, and n (1< a<b< 9,1sn< 10^6). Output: Print the answer modulo 1000000007 (10^9 + 7).
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY