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. HW1.1

    public class Solution { public static void main(String[] args) { System.out.println("Welcome to ...

  2. 路由器中pppoe,动态IP,静态IP的区别

    路由器中pppoe,动态IP,静态IP的区别 要把路由器设置得能上网,无非就是设置WAN外网接口连接而已.WAN接口能上网,则连接的电脑就能上网,反之则上不了网.只不过WAN接口往往有pppoe,动态 ...

  3. ORA-01653:表空间扩展失败的问题(开启表空间自动扩展)

    ----查询表空间使用情况---使用DBA权限登陆SELECT UPPER(F.TABLESPACE_NAME) "表空间名",D.TOT_GROOTTE_MB "表空间 ...

  4. light oj 1354 - IP Checking

    1354 - IP Checking   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB An I ...

  5. 高性能以太网芯片W5500 数据手册 V1.0(二)

    继续给大家介绍W5500 数据手册. 2.4       固定数据长度模式(FDM) 在外设主机不能控制 SCSn 时,可以使用固定数据长度模式. 此时,SCSn 必须连接到低电平(保持接地).与此同 ...

  6. fedora21安装xmind7

    老版本的xmind安装方法,在最后的阶段无法成功注册到系统中,desktop无法自定义完成.参考:http://www.cnblogs.com/cupcoffee/p/3560626.html 直到从 ...

  7. Java 中 String 类和StringBuilder 类的常用方法

    String 类提供了许多用来处理字符串的方法,例如,获取字符串长度.对字符串进行截取.将字符串转换为大写或小写.字符串分割等,下面我们就来领略它的强大之处吧. String 类的常用方法: 结合代码 ...

  8. jsp页面转发到servlet

    一个简单的例子来了解一下jsp页面转发到servlet的过程,环境 eclipse.tomcat 1.工程目录结构如下 2.各部分代码如下 1>index.jsp <%@ page lan ...

  9. Nginx/Apache图片缩略图技术

    1,目的 2,使用方式 3,Nginx + Linux 缩略图实现 3.1,原理 3.2,nginx配置实现 3.3,例子 4,Apache + Windows缩略图实现 4.1,环境 4.2,原理 ...

  10. apache配置directoryindex

    为了让程序自动执行目录下的某个文件,可以配置虚拟主机中的directoryindex 如: <VirtualHost *:80>    DocumentRoot "D:/var/ ...