3751: [NOIP2014]解方程

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 4856  Solved: 983
[Submit][Status][Discuss]

Description

已知多项式方程:

a0+a1*x+a2*x^2+...+an*x^n=0
求这个方程在[1,m]内的整数解(n和m均为正整数)。
 

Input

第一行包含2个整数n、m,每两个整数之间用一个空格隔开。
接下来的n+1行每行包含一个整数,依次为a0,a1,a2,...,an。

Output

第一行输出方程在[1,m]内的整数解的个数。

接下来每行一个整数,按照从小到大的顺序依次输出方程在[1,m]内的一个整数解。
 

Sample Input

2 10
2
-3
1

Sample Output

2
1
2

HINT

对于100%的数据,0<n≤100,|ai|≤1010000,an≠0,m≤1000000。


Solution

暴力枚举即可,难点主要是读入和快速计算。

大整数读入解决方法是mod大~质数,题解大佬说mod一个可能会出问题所以有时候要mod几个~

快速计算的话就是秦九韶公式了QAQ,很好理解的,不过这道题要控制mod的次数!不然多100次都t了QAQ!

Code

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define mod 1000000007
  4. using namespace std;
  5.  
  6. inline LL read() {
  7. LL x = ; int t = ; char ch = getchar();
  8. while(ch > '' || ch < '') { if(ch == '-') t = -; ch = getchar(); }
  9. while(ch >= '' && ch <= '') { x = ((x << ) % mod + (x << ) % mod + ch - '') % mod; ch = getchar(); }
  10. return x * t;
  11. }
  12.  
  13. LL a[];
  14. int n, m, ans[], tot;
  15. inline bool cal(int x) {
  16. LL res = a[n];
  17. for(int i = n - ; i >= ; i --)
  18. res = (res * x % mod + a[i]);
  19. return res == ;
  20. }
  21.  
  22. int main() {
  23. n = read(); m = read();
  24. for(int i = ; i <= n; i ++) a[i] = read();
  25. for(int i = ; i <= m; i ++)
  26. if(cal(i)) ans[++tot] = i;
  27. printf("%d\n", tot);
  28. for(int i = ; i <= tot; i ++)
  29. printf("%d\n", ans[i]);
  30. return ;
  31. }

【BZOJ】3751: [NOIP2014]解方程【秦九韶公式】【大整数取模技巧】的更多相关文章

  1. BZOJ 3751: [NOIP2014]解方程 数学

    3751: [NOIP2014]解方程 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=3751 Description 已知多项式方程: ...

  2. bzoj 3751: [NOIP2014]解方程 同余系枚举

    3.解方程(equation.cpp/c/pas)[问题描述]已知多项式方程:a ! + a ! x + a ! x ! + ⋯ + a ! x ! = 0求这个方程在[1, m]内的整数解(n 和 ...

  3. bzoj 3751: [NOIP2014]解方程

    Description 已知多项式方程: a0+a1x+a2x^2+...+an*x^n=0 求这个方程在[1,m]内的整数解(n和m均为正整数). 解题报告: 这题比较诡,看到高精度做不了,就要想到 ...

  4. bzoj 3751: [NOIP2014]解方程【数学】

    --我真是太非了,自己搞了7个质数都WA,从别人那粘5个质数就A了-- 就是直接枚举解,用裴蜀定理计算是否符合要求,因为这里显然结果很大,所以我们对多个质数取模看最后是不是都为0 #include&l ...

  5. poj2305-Basic remains(进制转换 + 大整数取模)

    进制转换 + 大整数取模一,题意: 在b进制下,求p%m,再装换成b进制输出. 其中p为b进制大数1000位以内,m为b进制数9位以内二,思路: 1,以字符串的形式输入p,m; 2,转换:字符串-&g ...

  6. cogs 2170. 大整数取模

    2170. 大整数取模 ★   输入文件:bigint.in   输出文件:bigint.out   简单对比时间限制:1 s   内存限制:256 MB [题目描述] 输入正整数n和m,输出n mo ...

  7. 【BZOJ】3751: [NOIP2014]解方程

    题意 求\(\sum_{i=0}^{n} a_i x^i = 0\)在\([1, m]\)内的整数解.(\(0 < n \le 100, |a_i| \le 10^{10000}, a_n \n ...

  8. hdu 4474 大整数取模+bfs

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4474 (a*10+b)%c = ((a%c)*10+b%c)%c; 然后从高位开始枚举能填的数字填充, ...

  9. LOJ2503 NOIP2014 解方程 【HASH】

    LOJ2503 NOIP2014 解方程 LINK 题目大意就是给你一个方程,让你求[1,m]中的解,其中系数非常大 看到是提高T3还是解方程就以为是神仙数学题 后来研究了一下高精之类的算法发现过不了 ...

随机推荐

  1. Codeforces #55D-Beautiful numbers (数位dp)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  2. poj 3686 Priest John's Busiest Day

    http://poj.org/problem?id=3683 2-sat 问题判定,输出一组可行解 http://www.cnblogs.com/TheRoadToTheGold/p/8436948. ...

  3. (32位)本体学习程序(ontoEnrich)系统使用说明文档

    系统运行:文件夹system下,可执行文件ontoEnrichment --------------------------------------------------------1.简单概念学习 ...

  4. javascript鼠标拖拽的那些事情

    <html> <head> <title>javascript鼠标拖拽的那些事情</title> <meta http-equiv="C ...

  5. 内置函数bytes()

    a=b'\x00\x9c@c' print a[3]#99,c的ascii码是99 print a[1]#156 并且byte是无法修改的 c[1]=155 Traceback (most recen ...

  6. Javascript - Vue - 指令

    指令 v-cloak 解决闪烁,闪烁是指在网速较慢的情况下可能会出现插值表达式{{}}还没有填充数据时会把该表达式直接显示在页面上,如果不希望看到插值表达式则可以使用v-cloak指令,具体做法如下 ...

  7. linux sftp安装【转】

    工具:虚拟机:VMware Workstation Pro.操作系统:CentOS-6.4-x86_64-minimal.终端模拟器:Xshell 5 .ftp:filezilla 一.让虚拟机联网 ...

  8. Linux 黑白界面显示

    2014年1月14日 15:47:47 不知道别人怎么看,反正我觉得黑白配显示很方便阅读 命令: ls 脚本: ~/.bashrc 指令: alias ls='ls --color=never' 命令 ...

  9. 查找网内活跃IP和自动传输文本

    ifconfig p32p1|egrep -o "broadcast [^ ]*" |grep -o "[0-9.]*"grep -o "broadc ...

  10. hdu 2065(泰勒展式)

    比赛的时候遇到这种题,只能怪自己高数学得不好,看着别人秒.... 由4种字母组成,A和C只能出现偶数次. 构造指数级生成函数:(1+x/1!+x^2/2!+x^3/3!……)^2*(1+x^2/2!+ ...