[BZOJ3751] [NOIP2014] Equation of solution (mathematics)

Source: Internet
Author: User

DescriptionKnown polynomial equation: $a_0+a_1*x+a_2*x^2+...+a_n*x^n=0$ to find the integer solution (n and M are positive integers) within [1,m].InputThe first line contains 2 integers n, m, separated by a space between each of the two integers. The next n+1 line contains an integer for each row, followed by A0,a1,a2,..., an.OutputThe number of integer solutions for the first line of the output equation in [1,m]. Next, an integer in each line, followed by an integer solution of the equation in [1,m], in order from small to large.Sample Input2 10
2
-3
1Sample Output2
1
2HINT

For 100% of data, 0<n≤100,|ai|≤10^10000,an≠0,m≤1000000.

SourceSolution

Considering the equivalent left-side overall confrontation number modulo, this part uses the Qin Jiushao algorithm implementation can greatly speed up, and can avoid a lot of high precision operation

Assuming the modulus is $p$, it is not difficult to find in the $p$ meaning of the $x$ and $x+kp$ obtained the same result, so we can preprocess out $[0,p) $ The answer, the introduction of $[1,m]$ may be the solution

Because $p$ is very small, there will be similar hash collisions happening, so we can select multiple $p$. It is said to choose $5$ a $20000$ around the prime number, but I have changed several prime numbers, not $wa$ is $tle$,qaq

The prime numbers in the code are found on the Internet, and it's unclear why this person's character can be so good qaq,$4$ a prime number $ac$qaq

(The method will be OK, this problem is not the selection of prime numbers, prime numbers copied on the line)

1#include <bits/stdc++.h>2 using namespacestd;3 Chars[ the][10005];4 intp[4] = {17389,22349,22367,22369};5 intN, a[ the], ans[1000005];6 BOOLvis[5][27005];7 8 BOOLCheckintx)9 {Ten     if(!vis[0][x%17389])return false; One     if(!vis[1][x%22349])return false; A     if(!vis[2][x%22367])return false; -     if(!vis[3][x%22369])return false; -     return true; the } -  - BOOLIs_zero (intKintx) - { +     Long LongAns =A[n]; -      for(inti = n-1; ~i; --i) +Ans = (ans * x + a[i])%P[k]; A     return!ans; at } -  - intMain () - { -     intm, tot =0; -scanf"%d%d", &n, &m); in      for(inti =0; I <= N; ++i) -scanf"%s", &s[i]); to      for(inti =0; I <4; ++i) +     { -Memset (A,0,sizeof(a)); the          for(intj =0; J <= N; ++j) *             if(s[j][0] =='-') $                  for(intK =1; S[J][K]; ++k)Panax NotoginsengA[J] = (a[j] *Ten-S[j][k] + -+ p[i])%P[i]; -             Else the                  for(intK =0; S[J][K]; ++k) +A[J] = (a[j] *Ten+ S[j][k]- -) %P[i]; A          for(intj =1; J < P[i]; ++j) theVIS[I][J] =Is_zero (i, j); +     } -      for(inti =1; I <= m; ++i) $         if(check (i)) ans[++tot] =i; $printf"%d\n", tot); -      for(inti =1; I <= tot; ++i) -printf"%d\n", Ans[i]); the     return 0; -}
View Code

[BZOJ3751] [NOIP2014] Equation of solution (mathematics)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.