Description

Mr. O'Cruel is teaching Math to ninth grade students. Students of course are very lazy, so they do not like to do their homework. On the other side, Mr. O'Cruel doesn't like lazy students.
Recently Andrew failed to do his homework again, so he was given a
special task. If he doesn't do it, he will be expelled from his school.
The task seems very easy, but it is very technical, so it would take a
lot of time. Andrew is given a polynomial p(x) = anxn + an-1xn-1 + . . . + a1x + a0 with integer coefficients.

He must calculate the value of the polynomial for k successive
integer numbers starting from l. Of course writing all these numbers
would require too much paper. So as a proof of completing the task, for
each number x from l to l + k - 1 Andrew is asked to provide the sum of
squares of m last digits in decimal notation of p(x).

Since Andrew is lazy, he doesn't want to do the task by himself. So
he asks you to write the program that calculates the values requested.

Input

The first line of the input file contains n, l, k, and m (0 <= n <= 10, 0 <= l <= 101000 , 1 <= k <= 1 000, 1 <= m <= 1 000).

The following n + 1 lines contain coefficients of the polynomial: an , an-1 , . . . , a1 , a0 (0 <= ai <= 101000).

Output

Output k lines --- for x from l to l + k - 1 output the sum of squares of last m digits of p(x).

Sample Input

3 0 10 2
1
0
2
1

Sample Output

1
16
10
25
58
45
85
89
85
80

Source

Northeastern Europe 2004, Northern Subregion
【分析】
差分序列是个比较有意思的东西。
题意:给出一个多项式p(x) = an * (x ^ n) + an-1 * (x ^ (n - 1)) + an-2 * (x ^ (n - 2)) .. a1 * x + a0,询问p(l)~p(l + k - 1)这些项的最后m位的平方和。
 
差分序列和伯努利数都可以在m ^ 2的时间内求自然数幂和,当然如果你用FFT求逆元伯努利数可以达到mlogm,但伯努利数的公式较为复杂,差分序列相对来说更好操作一些。
这道题是差分序列的裸题,直接做差分到n行,然后每次更新的时候只需要记录最后一行的值就好了。
 

【POJ2094】【差分序列】Angry Teacher的更多相关文章

  1. poj2094

    很不错的一道题,很让我见识到了差分序列的运用的神奇之处..一下是从北邮BBS看到的题解,写得很清楚..这边就直接转过来. uRLhttp://bbs.byr.cn/#!article/ACM_ICPC ...

  2. English trip V1 - 1.How Do You Feel Now? Teacher:Lamb Key:形容词(Adjectives)

    In this lesson you will learn to describe people, things, and feelings.在本课中,您将学习如何描述人,事和感受. STARTER  ...

  3. 设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。

    一.            设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...

  4. 【英语学习】2016.09.11 Culture Insider: Teacher's Day in ancient China

      Culture Insider: Teacher's Day in ancient China 2016-09-10 CHINADAILY Today is the 32nd Chinese Te ...

  5. poj 2515 差分序列,排列组合

    大神博客链接 http://blog.csdn.net/kksleric/article/details/8021276 这道题的差分序列从没看过,公式题. 先构造从0到m的第p阶差分序列,算出0^p ...

  6. Don't make a promise when you are in Joy. Don't reply when you are Sad.Don't take decisions when you are Angry.Think Twice.Act Wise.

    Don't make a promise when you are in Joy. Don't reply when you are Sad.Don't take decisions when you ...

  7. 对teacher表进行增加,删除,修改

    <%@page import="java.text.SimpleDateFormat"%> <%@ page language="java" ...

  8. 超强语感训练文章(Provided by Rocky teacher Prince)

    Content: Class1 My name is Prince Class2 Welcome to our hotel Class3 We’re not afraid of problems Cl ...

  9. hdu 5762 Teacher Bo 曼哈顿路径

    Teacher Bo Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tota ...

随机推荐

  1. HW3.8

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  2. Redis 数据库结构设计

    Redis设计参考资料: http://my.oschina.net/fsmwhx/blog/152130 http://my.oschina.net/1123581321/blog/164288 h ...

  3. DATASNAP复杂中间件的一些处理方法

    1.中间件需要连接SQL SERVER\ORACLE\MYSQL多种数据库,怎么办? [解决]:可以搞多种数据模块池对应多种数据库,一种数据模块池对应一种数据库 2.中间件业务对象多,在一个单元里面定 ...

  4. maven依赖规则

    1.就近原则,传递依赖 A-B-C -> A-C 2.先声明原则 A-B-C D-E-C 依赖的规则阻止了jar包冲突

  5. Linux为Tomecat指定JDK

    在搭建Jenkin+Sonar集成时,由于系统环境配置了jdk1.7,但是jenkins在安装sonar的插件时,需要jdk1.8.,所以需要在Tomcat指定jdk1.8. (1)暂停Tomcat ...

  6. C# ip hash算法实现ip分流

    private void button42_Click(object sender, EventArgs e) { Dictionary<int, string> proxyIpNodes ...

  7. powershell创建并加载配置文件

    $pshome :powershell的主目录 $profile :显示 Windows PowerShell 配置文件的路径 test-path $profile :确定是否已经在系统上创建了 Wi ...

  8. WPF中的StackPanel、WrapPanel、DockPanel

    一.StackPanel StackPanel是以堆叠的方式显示其中的控件 1.可以使用Orientation属性更改堆叠的顺序 Orientation="Vertical" 默认 ...

  9. CSharp Algorithm - How to traverse binary tree by breadth (Part II)

    /* Author: Jiangong SUN */ Here I will introduce the breadth first traversal of binary tree. The pri ...

  10. Interesting visualization tools for profiling.

    Interesting visualization tools for profiling. http://dtrace.org/blogs/brendan/2012/03/17/linux-kern ...