"Noip Tour" NOIP2014 day2 T3 solution equation

Source: Internet
Author: User

3 . Solution Equation

(Equation.cpp/c/pas)

"Problem Description described "

Known polynomial equation:

The integer solution of this equation in [1, M] (both N and m are positive integers).

Input

The input file name is equation.in.

Enter a total n+2 line.

The 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.

Output

The output file name is Equation.out.

The number of integer solutions in the first row of the output equation in [1, M].

Next, each line of an integer, according to the order from small to large output equation in [1, M] an integer solution.

"Input and output Example 1"

Equation.in

Equation.out

2 10

1

-2

1

1

1

"Input and output Example 2"

Equation.in

Equation.out

2 10

2

-3

1

2

1

2

"Input and output Example 3"

Equation.in

Equation.out

2 10

1

3

2

0

"Data description"

For 30% of data,0<n≤2,|ai|≤100,an≠0,m≤100;

For 50% of data,0<n≤100,|ai|≤10100,an≠0,m≤100;

For 70% of data,0<n≤100,|ai|≤1010000,an≠0,m≤10000;

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

Ideas

Taken from others.

By the size of a you can see that the topic should be mod a prime.

You only need to judge 1 in turn. Whether V in prime can make the equation 0 through the modulo prime, note that the for reverse enumeration is wise. The number of other numbers outside the M prime can be judged by the modulo prime mapping to the prime.

Try several primes to determine the answer.

Lesson: Sometimes the range of data can reflect the idea of a problem to a certain extent.

Code

1#include <cstdio>2#include <cstring>3 using namespacestd;4 Const intMAXN = -+5;5 Const intprimes[]={10007,10917,30071};6 7 Long Longa[maxn][3];8 BOOLf[100000][3];9 intcnt[1000010];Ten Chars[10010]; One intn,m; A intCalcintVintj) {//calculates if V is not able to pass modulo J and is 0 -     Long Longtmp=0; -      for(intI=n; i>=0; i--)//Reverse Enumeration theTmp= (Tmp*v+a[i][j])%Primes[j]; -      -     returntmp!=0; - } + intMain () { -scanf"%d%d",&n,&m); +      for(intI=0; i<=n;i++) { Ascanf"%s", s); at         intlen=strlen (s); -         intsign=1;  -          for(intL=0; l<len;l++)  -             if(s[l]=='-') sign=-1; -             Else   -                for(intj=0;j<3; j + +)  inA[i][j]= (a[i][j]*Ten+s[l]-'0')%Primes[j]; -         if(sign==-1)//Convert Symbols to           for(intj=0;j<3; j + +) +a[i][j]=primes[j]-A[i][j]; -     } the      *      for(intj=0;j<3; j + +)  $       for(intI=0; i<primes[j];i++)//i from [0..primes[j]]Panax Notoginsengf[i][j]=Calc (i,j); -      the      for(intI=1; i<=m;i++) { +        intflag=true;  A         for(intj=0;j<3; j + +)if(F[i%primes[j]][j]) {//I%primes[j] Conversion theflag=false; Break; +        } -        if(flag) cnt[++cnt[0]]=i; $     } $printf"%d\n", cnt[0]); -     if(cnt[0]) for(intI=1; i<=cnt[0];i++) printf ("%d\n", Cnt[i]); -     return 0; the}

"Noip Journey" NOIP2014 day2 T3 solution equation

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.