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: */
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...
Related questions
Question
Please do this on JAVA
![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:
* /](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F600d901b-3a9c-406d-8f79-73feba69cfdc%2Fe51ee92e-b375-4f39-b6fe-fcb093134227%2F5wkdpzd_processed.png&w=3840&q=75)
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).](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F600d901b-3a9c-406d-8f79-73feba69cfdc%2Fe51ee92e-b375-4f39-b6fe-fcb093134227%2Fvi252o_processed.png&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
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](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY