Example 1: Solve the below programming question using Python Dr.D is tired of making up stories, so here is the formal description of this problem : You are given a set S = {S1,S2,….., Sx}, an integer X and a sequence A1, Az, ..., AM. Let's define an infinite sequence W1, W2,...: for each valid i, W, = A(«-19%M)+1- Then, let's define a function F(i) for any non-negative integer i in the following way: • F(0) = X • ifie S. F(i) = 0 • otherwise, for i 4 0, F(i) = (E-, F(i – 5) · W;) %(10° + 7) Find the value of F(N).

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
icon
Related questions
Question
Example 1: Solve the below programming question using Python
Dr.D is tired of making up stories, so here is the formal description of this problem :
You are given a set S = {S1, S2,..., Sk}, an integer X and a sequence
A1, A2,..., AM. Let's define an infinite sequence W1, W2,...: for each valid i,
W; = A((i-1)%M)+1. Then, let's define a function F(i) for any non-negative
integer i in the following way:
%3D
• F(0) = X
• if i e S. F(i) = 0
• otherwise, for i + 0, F(i) = (E-1 F(i – j) - W,) %(10° + 7)
%3D
Find the value of F(N).
Sample Input:
3135
4
231
Sample Output:
231
Transcribed Image Text:Example 1: Solve the below programming question using Python Dr.D is tired of making up stories, so here is the formal description of this problem : You are given a set S = {S1, S2,..., Sk}, an integer X and a sequence A1, A2,..., AM. Let's define an infinite sequence W1, W2,...: for each valid i, W; = A((i-1)%M)+1. Then, let's define a function F(i) for any non-negative integer i in the following way: %3D • F(0) = X • if i e S. F(i) = 0 • otherwise, for i + 0, F(i) = (E-1 F(i – j) - W,) %(10° + 7) %3D Find the value of F(N). Sample Input: 3135 4 231 Sample Output: 231
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Fibonacci algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr