/**
给出多项式 p(x) = an*x^n + an-1*x^(n-1)..... + a1*x + a0;
给定n,l,k,m 计算 x 从 l到 l+k-1 的p(x)的后m 位的平方的和 用差分序列 ,先计算出前 n项 构造出差分表。。后边的k-n个 用递推可得,从下往上递推。
**/ import java.math.BigInteger;
import java.util.Scanner; public class Main { public static int cal(String str, int m) {
// System.out.println(str+"------->");
int len = Math.min(str.length(), m);
int ans = , tmp;
for (int i = ; i < len; i++) {
tmp = str.charAt(i) - '';
ans += tmp * tmp;
}
return ans;
} public static void main(String[] args) {
Scanner cin = new Scanner(System. in);
int n = cin.nextInt();
BigInteger l = cin.nextBigInteger();
int k = cin.nextInt();
int m = cin.nextInt();
BigInteger mod = BigInteger. TEN.pow(m);
BigInteger[] a = new BigInteger[];
for (int i = ; i <= n; i++)
a[i] = cin.nextBigInteger();
BigInteger h[][] = new BigInteger[][];
for (int i = ; i < Math.min (n + , k); i++) {
BigInteger res = a[];
for (int j = ; j <= n; j++) {
res = res.multiply(l);
res = res.add(a[j]);
}
res = res.mod(mod);
l = l.add(BigInteger. ONE);
h[][i] = res;
System. out.println(cal(res.toString(), m));
} if (k > n + ) {
for (int i = ; i <= n; i++) {
for (int j = ; j <= n - i; j++)
h[i][j] = h[i - ][j + ].subtract(h[i - ][j]);
}
} BigInteger pre[] = new BigInteger[];
for (int i = ; i <= n; i++) {
pre[i] = h[i][n - i];
}
for (int i = n + ; i < k; i++) {
BigInteger res = h[n][];
for (int j = n - ; j >= ; j--) {
res = pre[j].add(res);
res = res.mod(mod);
pre[j] = res;
}
System. out.println(cal(res.toString(), m));
}
} }

poj 2094 多项式求和。的更多相关文章

  1. HDOJ2011多项式求和

    多项式求和 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  2. 多项式求和 AC 杭电

    多项式求和 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  3. 多项式求和,素数判定 HDU2011.2012

    HDU 2011:多项式求和 Description 多项式的描述如下: 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + ... 现在请你求出该多项式的前n项的和.   Input ...

  4. SDUT OJ 多项式求和

    多项式求和 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Description 多项式描述 ...

  5. hdu2011 多项式求和【C++】

    多项式求和 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  6. Java练习 SDUT-2504_多项式求和

    多项式求和 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 多项式描述如下: 1 - 1/2 + 1/3 - 1/4 + ...

  7. 练习2 J题 - 多项式求和

      Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description 多项式 ...

  8. HDOJ 2011 多项式求和

    Problem Description 多项式的描述如下: 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + - 现在请你求出该多项式的前n项的和. Input 输入数据由2行组成, ...

  9. HDU 2011 多项式求和

    http://acm.hdu.edu.cn/showproblem.php?pid=2011 Problem Description 多项式的描述如下:1 - 1/2 + 1/3 - 1/4 + 1/ ...

随机推荐

  1. 张王李相亲应用if else

    package hello; public class to { public static void main(String[]args){ int a =1,b=0; int c =1,d=0; ...

  2. Android项目中包名的改动

    通常改动包名时会造成R文件错误,而且有时带有原因不明的Manifest文件里多处文本混乱. 所以,将眼下觉得最为简洁方便的改动包名流程记录例如以下: 如果我们眼下的包名为com.pepper.util ...

  3. Ubuntu14(64位) 集群环境下安装Hadoop2.4

    经过前边的积累,今天最终实现了集群环境下部署Hadoop.并成功执行了官方的样例. 工作例如以下: 两台机器: NameNode:上网小本,3G内存.机器名:YP-X100e,IP:192.168.1 ...

  4. Android Intent的几种使用方法全面总结

    Intent应该算是Android中特有的东西.你能够在Intent中指定程序要运行的动作(比方:view,edit,dial),以及程序运行到该动作时所须要的资料.都指定好后,仅仅要调用startA ...

  5. sql update 触发器 可获得被update的行的信息

    类型:转载   sql update 触发器 可获得被update的行的信息,需要的朋友可以参考下. 复制代码 代码如下: create trigger TgName on tb for update ...

  6. Unity UGUI在鼠标位置不同时 图片浮动效果

    /// <summary> /// 在鼠标位置不同时 图片浮动效果 /// </summary> public class TiltWindow : MonoBehaviour ...

  7. CTRL+A, CTRL+C, CTRL+V

    (http://leetcode.com/2011/01/ctrla-ctrlc-ctrlv.html) Imagine you have a special keyboard with the fo ...

  8. MQTT协议详解一

    首先给出MQTT协议的查看地址:http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html 当然也有PDF版的,百 ...

  9. 初识python yield

    for sel in response.xpath('//ul/li'): item = DmozItem() item['title'] = sel.xpath('a/text()').extrac ...

  10. [LeetCode]题解(python):070-Climbing Stairs

    题目来源: https://leetcode.com/problems/climbing-stairs/ 题意分析: 爬楼梯,一次可以爬一步或者两步.如果要爬n层,问一共有多少种爬法.比如说,如果是3 ...