NOIP201410 solution equation (c + +)

Source: Internet
Author: User

Equation of NOIP201410 Solution
Difficulty level: A; run time limit: 1000ms; operating space limit: 51200KB; code length limit: 2000000B
Question Description
Known polynomial equation: a0+a1*x+a2*x^2+a3*x^3+...+an*x^n=0 The integer solution of this equation within [1, M] (both N and m are positive integers).
Input
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 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 example
2 10
2
-3
1
Output example
2
1
2
Other Notes
For 100% of data, 0 < n≤100, ai≤10^10000, an≠0,m≤1000000.

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 110
using namespace Std;
typedef long Long LL;
const int prime[]={30011,11261,14843,19997,10007,21893};
int n,m,stack[1001001],top;
int Ans[110],tot;
ll A[m][6],f[30011][6];
inline ll F (int x,int j)
{
int i;
ll Re=0;
for (i=n;~i;i--)
Re= (Re*x+a[i][j])%prime[j];
return re;
}
inline void Input (int x)
{
static Char s[10100];
int i,j;
BOOL Flag=false;
scanf ("%s", s+1);
for (i=1;s[i];i++)
{
if (s[i]== '-')
Flag=true;
Else
for (j=0;j<6;j++)
A[x][j]= ((a[x][j]<<1) + (a[x][j]<<3) + s[i]-' 0 ')%prime[j];
}
if (flag)
for (j=0;j<6;j++)
A[X][J]=PRIME[J]-A[X][J];
}
int main ()
{

Freopen ("Equation.in", "R", stdin);

int i,j;
cin>>n>>m;
for (i=0;i<=n;i++)
Input (i);

for (j=0;j<6;j++)
for (i=0;i<prime[j];i++)
F[i][j]=f (I,J);

for (i=0;i<prime[0];i++)
{
if (f[i%prime[0]][0]==0)
Stack[++top]=i;
}

for (i=1;i<=top;i++)
{
if (stack[i]+prime[0]>m)
Break
STACK[++TOP]=STACK[I]+PRIME[0];
}

for (i=1;i<=top;i++)
{
if (stack[i]>m)
Break
for (j=1;j<6;j++)
if (F[stack[i]%prime[j]][j])
Break
if (j==6)
Ans[++tot]=stack[i];
}

cout<<tot<<endl;
for (i=1;i<=tot;i++)
printf ("%d\n", Ans[i]);
}

NOIP201410 solution equation (c + +)

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.