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. POJ-1981 Circle and Points 单位圆覆盖

    题目链接:http://poj.org/problem?id=1981 容易想到直接枚举两个点,然后确定一个圆来枚举,算法复杂度O(n^3). 这题还有O(n^2*lg n)的算法.将每个点扩展为单位 ...

  2. ios 免书籍入门站点

    http://www.raywenderlich.com/tutorials http://www.raywenderlich.com/ios-tutorials http://web.stanfor ...

  3. position与anchorPoint

    相信初接触到CALayer的人都会遇到以下几个问题: 为什么修改anchorPoint会移动layer的位置?CALayer的position点是哪一点呢?anchorPoint与position有什 ...

  4. jQuery进行图片预先加载

    /** **将图片加载到内存中,在页面任何位置引用的时候,直接从缓存中读取,提升用户的体验,提高网站的流畅度.** **/ <!DOCTYPE html PUBLIC "-//W3C/ ...

  5. Centos6.3建立FTP

    2014年2月22日 16:54:20 1. 安装ftp     yum install vsftpd ftp 2. 编辑/etc/vsftpd/vsftpd.conf     chroot_list ...

  6. 使用cxf写web service的简单实例

    增加CXF依赖 <dependency> <groupId>org.apache.cxf</groupId> <artifactId>apache-cx ...

  7. Java获取泛型的Class对象

    工作中瞄到的,在此收集了 public class RawDao<T> { protected Class<T> clazz; @SuppressWarnings(" ...

  8. IOS 获取屏幕尺寸

    CGRect frame = [[UIScreen mainScreen] bounds];    NSLog(@"frame :%@",frame); 这样输入是null NSL ...

  9. C# 算速表达式

              public object ComputeExpression(string expression)         {             var result = new  ...

  10. 分布式助手Zookeeper(一)

    分布式助手Zookeeper(一)博客分类: Zookeeper   Zookeeper最早是Hadoop的一个子项目,主要为Hadoop生态系统中一些列组件提供统一的分布式协作服务,在2010年10 ...