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. Apple LLVM 6.0 Warning: profile data may be out of date

    I have no clue what this meant, so I googled the problem. I only ended up with some search results s ...

  2. void,extern,sizeof

    高手潜规则:禁用goto 程序质量与goto出现次数成反比 void指针的意义 1.C语言规定只有相同类型的指针才可以相互赋值 2.void*指针作为坐值用于"接收"任意类型的指针 ...

  3. python学习(3)

    Python学习(3)切片(Slice):根据索引范围取出字符串里面的内容,比如: l=range(100)   l[:8] [0, 1, 2, 3, 4, 5, 6, 7]              ...

  4. MySQL bug:server-id默认被自己主动置为1

    昨天同事在做主从时,从库报例如以下错误: Got fatal error 1236 from master when reading data from binary log: 'Misconfigu ...

  5. ListBox基础

    关键点   在列表框生成后需要向其中加入或是删除行,可以利用: int AddString( LPCTSTR lpszItem )添加行, int DeleteString( UINT nIndex ...

  6. RedHat Enterprise Linux 6.4使用Centos 6 的yum源 分类: 服务器搭建 Nginx 2015-07-14 14:11 5人阅读 评论(0) 收藏

    转载自:http://blog.sina.com.cn/s/blog_50f908410101cto6.html 思路:卸载redhat自带yum,然后下载centos的yum,安装后修改配置文件 1 ...

  7. android照片墙的实现

    转载自 http://blog.csdn.net/guolin_blog/article/details/9526203 由于每个android应用程序都有内存限制,所以如果加载很多图片的话,一定会出 ...

  8. cocos2d-x 2.1.4学习笔记01:windows平台搭建cocos2d-x开发环境

    cocos2d-x的大致开发流程是,首先使用win32版进行代码编写并完成游戏,然后将代码迁移到对应的开发环境上进行交叉编译完成游戏打包,如iphone上是mac+xcode,android是ecli ...

  9. 操作系统-mac安装linux(Ubuntu)

    mac安装linux 安装linux,分为两步: 1. 制作linux启动U盘 2. 通过启动U盘,安装Ubuntu系统 Mac OS X下创建USB启动盘 格式化USB驱动盘 下载Ubuntu桌面版 ...

  10. 自定义ContentProvider

    ContentProvider作为安卓的四大组件之一,在看开发中用到的频率远不如其他三个,以至于我都把这个东西给忘了,最近由于工作原因,不得不重新拾起来总结一下,那么今天就来说说自定义ContentP ...