P2312 solving equations
Title Description
Known polynomial equation:
\[a_0+a_1x+a_2x^2+\cdots+a_nx^n=0\]
In [1, m] [1, m] in this equation find integer solutions ( \ (n-\) and \ (m \) are both positive integers).
Input Format
The input common $ n + 2 $ rows.
The first line contains \ (2 \) integers \ (n-, m \) , each between two integers separated by a space.
The next \ (n + 1 \) lines contains an integer, followed by \ (a_0, A_1, A_2 \ ldots A_N \) .
Output Format
Output line number of the first equation [1, m] [1, m] in the integer solution.
Next, each line an integer, an integer in the equation [1, m] [1, m] in solution in the order from small to large are sequentially output.
Sample input and output
Input # 1
2 10
1
-2
1
Output # 1
1
1
Input # 2
2 10
2
-3
1
Output # 2
2
1
2
Input # 3
2 10
1
3
2
Output # 3
0
Description / Tips
30% 30% For Data: \ (0 <n-\ Le 2, | a_i | \ Le 100, A_N ≠ 0, m <100 \) .
50% 50% For Data: \ (0 <n-\ Le 100, | a_i | \ Le ^ {10} 100, A_N ≠ 0, m <100 \) .
70% 70% For Data: \ (0 <n-\ Le 100, | a_i | \ Le ^ {10} 10000, A_N ≠ 0, m <10. 4 ^ \) .
To 100% 100% Data: \ (0 <n-\ Le 100, | a_i | \ Le ^ {10} 10000, A_N ≠ 0, m <10. 6 ^ \) .
[Thinking]
Qin Jiushao formula mode + + fast read mathematics, number theory
[Title] effect
Given the number of solutions required range within the range of the equation
[Analysis] title
m <= 1e6, can enumerate
so enumerate m is a good choice
equation solver? Algebra can try
but algebraic complexity is too high
can be broken with a look Qin Jiushao formula
does not explain the words to see the back of, or Baidu, remember formulas like very simple
to reduce complexity
[Core] ideas
Enumeration m
and m is not to judge what equations
only need to m into the equation try
NOTE: The
equation of the equation here after Qin Jiushao formulas decomposition
and then output the final count recorded answers like
[HataKyu 韶公 formula]
\ (a_0 + + a_2x a_1x ^ 2 + .... + a_3x. 3 ^ + ^ n-a_nx \)
\ (X = a_0 + (A_1 a_2x + + 2 + .... + a_3x a_nx ^ {^. 1-n- }) \)
\ (= .... \)
is the top way this
can be of the party which did not several times
the number of unknowns are the first power of the situation
so that you can reduce a lot of computation
[Complete code]
#include<iostream>
#include<cstdio>
#define int long long
using namespace std;
const int p = 1e9 + 7;
inline int read()
{
int sum = 0,fg = 1;
char c = getchar();
while(c < '0' || c > '9')
{
if(c == '-')fg = -1;
c = getchar();
}
while(c >= '0' && c <= '9')
{
sum = ((sum * 10) + c - '0') % p;
c = getchar();
}
return sum * fg;
}
int a[105];
int ans[1000006];
int n,m;
bool check(int x)
{
int sum = 0;
for(register int i = n;i >= 1;i --)
{
sum = (x * (a[i] + sum)) % p ;
}
sum = (sum + a[0]) % p;
if(sum == 0)return true;
else return false;
}
signed main()
{
freopen("au.out","r",stdin);
n = read();m = read();
for(register int i = 0;i <= n;++ i)
a[i] = read();
int js = 0;
for(register int i = 1;i <= m;++ i)
if(check(i) == true)
ans[++ js] = i;
cout << js << endl;
for(register int i = 1;i <= js;++ i)
cout << ans[i] << endl;
return 0;
}