【POJ2094】【差分序列】Angry Teacher

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行,然后每次更新的时候只需要记录最后一行的值就好了。

时间: 2024-10-10 00:47:40

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

uva 1489 - Math teacher&#39;s homework(数位dp)

题目链接:uva 1489 - Math teacher's homework 题目大意:给定n,k,以及序列m1,m2,-,mn, 要求找到一个长度为n的序列,满足0<=xi<=mi, 并且x1XORx2XOR-XORxn=k 解题思路:数位dp,在网上看了别人的代码,高大上... 假设有二进制数 k : 00001xxxx mi:0001xxxxx, 那么对于xi即可以满足任意的x1XORx2XOR-XORxi?1XORxi+1XOR-XORxn,根据这一点进行数位dp. dp[i][j]

设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1-2的表(一)~表(四)所示。用SQL语句创建四个表并完成相关题目。

表(一)Student (学生表) -- Create table create table STUDENT ( sno VARCHAR2(3) not null, sname VARCHAR2(8) not null, ssex VARCHAR2(2) not null, sbirthday DATE, class VARCHAR2(5) ) tablespace USERS pctfree 10 initrans 1 maxtrans 255; -- Add comments to the

练习:读取解析CSV文件,将读取结果输出的控制台上,并封装到4个Teacher对象中.

/** *    读取解析CSV文件,将读取结果输出的控制台上,并封装到4个Teacher对象中. *    1, 土鳖, 13101015338, 北京海淀区 2, 咪咪, 13201015338, 北京朝阳区 3, 小仓, 13601015818, 北京宣武区 4, 饭岛爱, 13201025818, 北京朝阳区 /** * 读取解析CSV文件,将读取结果输出的控制台上,并封装到4个Teacher对象中. * 1, 土鳖, 13101015338, 北京海淀区 2, 咪咪, 13201015

Problem 1567 - D - Sloth&#39;s Angry ( 递归+贪心)

Problem 1567 - D - Sloth's Angry Time Limit: 1000MS Memory Limit: 65536KB Total Submit: 326 Accepted: 113 Special Judge: No Description A forest is full of sloths, they are so eager for tree leaves and as a result, very angry. We assume that the fore

UVA 1397 - The Teacher&#39;s Side of Math(高斯消元)

UVA 1397 - The Teacher's Side of Math 题目链接 题意:给定一个x=a1/m+b1/n,求原方程组 思路:由于m*n最多20,所有最高项只有20,然后可以把每个此项拆分,之后得到n种不同无理数,每一项为0,就可以设系数为变元,构造方程进行高斯消元 一开始用longlong爆了,换成分数写法也爆了,又不想改高精度,最后是机智的用了double型过的,不过用double精度问题,所以高斯消元的姿势要正确,并且最后输出要注意-0的情况 代码: #include <c

Vijos P1782 借教室 ( 前缀和&amp;&amp;差分序列)

题目链接:借教室 题意:给出n天得教室数目,m个借教室得单子,按顺序借教室,问哪个单子不满足并输出 分析:可以用线段树做,会T,常数比较大,选择用差分序列维护前缀和,二分答案即可 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 6 int ans,n,m,r[1001000],d[1001000],s[1001000],t[1001000],pre

Teacher implements java.io.Serializable

package JBJADV003; public class Teacher implements java.io.Serializable{ private String name; private int age; private String gender; private transient String password; //包含引用类型数据属性 private Student stu; public Teacher(String name,Student stu){ this.n

hdu 5069 Harry And Biological Teacher

Harry And Biological Teacher Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 38    Accepted Submission(s): 6 Problem Description As we all know, Harry Porter learns magic at Hogwarts School. How

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

<%@page import="java.text.SimpleDateFormat"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*"%> <!DOCTYPE html PUBLI