[NOIP2014] solving equations, noip2014 Solving Equations

Source: Internet
Author: User

[NOIP2014] solving equations, noip2014 Solving Equations
3732 Solving Equations

 

Time Limit: 1 s space limit: 128000 KB title level: Diamond QuestionDescription Description

Input description Input Description

The input file name is equation. in.

Enter n + 2 rows in total.

The first line contains two integers, n and m. Each integer is separated by a space.

The next n + 1 line contains an integer, Which is a0, a1, a2 ,......, An.

 

Output description Output Description

The output file name is equation. out.

The number of Integer Solutions of the first line Output Equation in [1, m.

Next, an integer is generated in the order from small to large, and an integer solution of the equation in [1, m] is output in sequence.

 

 

Sample Input Sample Input

Equation. in

Equation. out

2 10

1

-2

1

 

1

1

Equation. in

Equation. out

2 10

2

-3

1

 

2

1

2

 

Sample output Sample Output

Equation. in

Equation. out

2 10

1

3

2

 

0

Data range and prompt Data Size & Hint

CATEGORY tag Tags click here to expandNOIP National League Promotion Group 2014
1/* 2 well, rp is very important. (RP ++ ). 3. This question requires a valid solution in the range [1, m. 4. However, m is a very large number. 5. If accuracy is not taken into account, o (nm) should be feasible 6 (I am so witty with FFT) 7 (Voiceover: 10 ^ 10000 pressure position + processing should be T bar orz) 8 so let's consider the solution of this equation in the sense of residue. 9 (ax) % p is equivalent to (ax + p) % p.10 we mod two prime.11 because mod one prime solution may be inadequate. 12. Finally, scan the valid solution from [1, m. 13 */14 # include <iostream> 15 # include <cstring> 16 # include <cstdio> 17 # define MAXN 20118 # define MAXM 100000119 # define LL long long20 using namespace std; 21 int n, M, ans, p [4]; 22 LL a [3] [MAXM]; 23 bool B [MAXM]; 24 char s1 [MAXM]; 25 void slove1 (char s [], int l, int k) 26 {27 bool flag = false; 28 int x; 29 for (int I = 1; I <= 2; I ++) 30 {31 x = 0; 32 if (s [0] = '-') x = 1, flag = true; 33 while (x <l) a [I] [k] = (a [I] [k] * 10% p [I] + s [x]-48) % p [I], x ++; 34 if (flag) a [I] [k] = p [I]-a [I] [k]; // negative number. 35} 36} 37 bool check (int x, int k) 38 {39 LL tot = 0, w = 1; 40 for (int I = 0; I <= n; I ++) 41 tot = (tot + a [k] [I] * w % p [k]) % p [k], W = (w * x) % p [k]; 42 return tot % p [k]; 43} 44 void slove () 45 {46 for (int I = 1; I <= p [1]; I ++) 47 {48 if (check (I, 1) continue; 49 for (int j = I; j <= m; j + = p [1]) 50 if (! Check (j, 2) B [j] = true; 51} 52 int tot = 0; 53 for (int I = 1; I <= m; I ++) 54 if (B [I]) tot ++; 55 printf ("% d \ n", tot); 56 for (int I = 1; I <= m; I ++) 57 if (B [I]) printf ("% d \ n", I); 58} 59 int main () 60 {61 p [1] = 22861, p [2] = 1000007977; 62 scanf ("% d", & n, & m ); 63 for (int I = 0; I <= n; I ++) 64 {65 cin> s1; 66 int l = strlen (s1); 67 slove1 (s1, l, I); 68} 69 slove (); 70 return 0; 71}

 

Related Article

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.