We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Dynamic Programming
  4. Find the Seed

Find the Seed

Problem
Submissions
Leaderboard
Discussions
Editorial

A company needs random numbers for its operation. random numbers have been generated using numbers as seeds and the following recurrence formula:

The numbers used as seeds are . is the term of the recurrence.

Due to a failure on the servers, the company lost its seed numbers. Now they just have the recurrence formula and the previously generated random numbers.

The company wants to recover the numbers used as seeds, so they have hired you for doing this task.

Input Format

The first line contains two space-separated integers, and , respectively.
The second line contains the space-separated integers describing (all these numbers are non-negative integers ).
The third line contains the space-separated coefficients of the recurrence formula, . All of these coefficients are positive integers .

Constraints

Output Format

The output must be one line containing the space-separated seeds of the random numbers - .

Sample Input

2 6
13 8
1 1

Sample Output

1 1 

Explanation

This is the classic Fibonacci recurrence. We have the and terms, and, of course, the seeds are the numbers and .

Author

vlade087

Difficulty

Advanced

Max Score

100

Submitted By

847

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature