方程式を解く問題に羅区P2312ソリューション
タイトル説明
既知の多項式:
\ [A_0 + a_1x + a_2x ^
2 + \ cdots + a_nx ^ N = 0 \] 式求めて\([1、m]を\ ) (内の整数解(\ \ N-)と\(m個\)でありますそれは)正の整数です。
入力形式
入力コモン\(N + 2 \)ライン。
最初の行は含ま\(2 \)整数\(N、M \) 、スペースで区切られた2つの整数の間でそれぞれ。
次の(n + 1 \)\続く行は整数を含み、\(A_0、A_1、A_2 \ ldots A_N \) 。
出力フォーマット
出力方程式の最初の行における\([1、M] \ ) 溶液中の整数の数。
次に、小から大へ順に各行溶液の整数、式中の整数[1、M] [1、m]は順次出力されます。
サンプル入力と出力
入力#1の複製
2 10
1
-2
1
コピー出力#1
1
1
入力#2のコピー
2 10
2
-3
1
コピー出力#2
2
1
2
入力#3のコピー
2 10
1
3
2
コピー出力#3
0
説明/プロンプト
のための\(30%\)のデータ:\(0 <N- \ル2 \) 、\(| a_iを| \ル100 \) 、\(A_N≠0 \) 、\(M <\ 1000 )
のための\(50%\)のデータ:\(0 <N- \ル100、| a_iを| \ル10 ^ {100}、A_N≠0、M <\ 1000)
する(70%\)\データ:\(0 <N -ル100、\ | a_iを| \ル^ {10} 10000、A_N≠0、M <10 4 ^ \。)。
以下のための\(100%\)のデータ:\(0 <N- \ル100、| a_iを| \ル^ {10} 10000、A_N≠0、M <10 6 ^ \。) 。
解像度:
秦九韶式+高速読み
入力ので、留意されるべき入力を\([I] \)は比較的広い範囲、
それが素数を法よう\(1 \)する(M \)\列挙し、列挙されている(X-を\)\、そして次に秦九韶を解決するための式を使用し返された値がある場合(\ 0 \) 、レコード一方が継続します。
#include <cstdio>
#include <iostream>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#define Max 105
#define re register
#define D double
#define int long long
int n,m,a[Max],ans = 0, Ans[1000012];
const int mod = 19260817;
int read() {
char ch = getchar(); int f = 1, s = 0;
while(ch < '0' || ch > '9') {
if(ch == '-') f = -1;
ch =getchar();
}
while(ch >= '0' && ch <= '9') {
s = (10 * s + ch - '0') % mod;
ch = getchar();
}
return s * f;
}
int work(int x) {
int ANS = 0;
for(re int i = n ; i >= 1 ; -- i)
ANS = ((ANS + a[i]) * x)% mod;
ANS = (ANS + a[0]) % mod;
return ANS;
}
void Main() {
scanf("%lld%lld",&n,&m);
for(re int i = 0; i <= n; ++ i) a[i] = read();
for(re int i = 1; i <= m; ++ i)
if(work(i) == 0) ans ++, Ans[ans] = i;
printf("%lld\n",ans);
for(re int i = 1; i <= ans; ++ i) printf("%lld\n",Ans[i]);
}
signed main() {
Main();
return 0;
}