Angry Teacher
Time limit1sMemory limit128 MB
For each of k consecutive integers starting at l, evaluate a polynomial with huge integer coefficients and output the sum of squares of the last m decimal digits of the value.
- Level
Medium6 of 10
- Topics
- Math, Implementation, Brute force, Number theory
- Solved
- No attempts yet
Problem
Mr. O'Cruel teaches Math to ninth-grade students. Students are usually lazy and dislike doing their homework, and Mr. O'Cruel dislikes lazy students.
Andrew failed to do his homework again, so he was given a special task. If he does not finish it, he will be expelled from school. The task looks easy, but it is very tedious and takes a lot of time.
Andrew is given a polynomial with integer coefficients. He must evaluate the polynomial for consecutive integers starting from . Writing down all of these values would take far too much paper, so as proof that he completed the task, for each from to Andrew must report the sum of the squares of the last digits of in decimal notation.
If has fewer than digits, treat the missing higher-order digits as zeros (their squares add nothing to the sum).
Since Andrew is lazy and does not want to do this himself, write the program that computes the requested values for him.
Input
The first line contains , , , and (, , , ).
The next lines contain the coefficients of the polynomial , one per line ().
Output
Output lines. For from to , output the sum of the squares of the last digits of .