Equation of P2312 Solution

 Topic provider The user does not exist
 Tag number theory (mathematicsrelated) highprecision Noip raising group
 Difficulty Increase +/province selection
Submit a discussion of the problem record
Recent discussions
 To correct the range of data
Title Description
Known polynomial equation:
a0+a1x+a2x^2+. +anx^n=0
The integer solution of this equation in [1, M] (both N and m are positive integers)
Input output Format input format:
The input file name is equation. In.
Enter a total of n + 2 rows.
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 format:
The output file is named 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 Sample input example # #:
2 10 121
Sample # # of output:
11
Input Sample #:
2 10231
Output Example #:
212
Input Sample # #:
2 1 3 2
Output Sample # #:
0
Description
30%:0<n<=2,ai<=100,an!=0,m<100
50%:0<n<=100,ai<=10^100,an!=0,m<100
70%:0<n<=100,ai<=10^10000,an!=0,m<10000
100%:0<n<=100,ai<=10^10000,an!=0,m<1000000
Analysis: A long time ago, Abel proved that the unary nth equation (n >= 5) is not the root formula, it seems that only 30% of the data can be violent, how can AC? It's about narrowing the data. It can be noted that AI and M are very large, m can't seem to shrink, how does ai shrink? Notice that this is an equation, then is the modulo operation, because to make the result of the equation is equal to 0, if f (x) = = 0, then f (x) mod p = = 0, but the converse does not necessarily set up, but if more than one enumeration of several p, the likelihood of AC is relatively large, less enumeration will WA, the enumeration This is the time to look at the face, this time to take a 10000 or so of prime numbers and a larger prime number (greater than M), why take prime? If AI equals 0 Then there is no point. Do you want an enumeration of x? It's too slow to notice that if f (x) mod p = = 0, then f (x + P) mod p = f (x) mod p + p mod p = = 0, so we add p on the basis of X continuously. In the calculation, once it is possible to exceed P, MoD.
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;Chars[10010];intp[3], N, m;Long Longa[3][ the];BOOLcan[1000010];voidQuyu (Char*S1,intk) { BOOLFu =false; intLen =strlen (S1), I; for(intj =1; J <=2; J + +) {i=0; if(s1[0] =='') {Fu=true; I=1; } for(; i < Len; i++) A[j][k]= (a[j][k] * 10LL% p[j] + s[i]'0') %P[j]; if(Fu = =true) A[j][k]= P[j]A[j][k]; }}intPanduan (intXintk) { Long LongAns =0, B =1; for(inti =0; I <= N; i++) {ans= (ans + 1LL * a[k][i] * b)%P[k]; b= 1LL * b * x%P[k]; } returnAns%p[k];}intMain () {p[1] =67891, p[2] =1000000207;//Two prime numbersscanf"%d%d", &n, &m); for(inti =1; I <= m; i++) Can[i]=false; for(inti =0; I <= N; i++) {scanf ("%s", s); Quyu (S, i); } for(inti =1; I <= p[1]; i++) { if(Panduan (I,1) !=0) Continue; for(intj = i; J <= M; J + = p[1]) if(Panduan (J,2) ==0) Can[j]=true; } intAns =0; for(inti =1; I <= m; i++) if(Can[i]) ans++; printf ("%d\n", ans); for(inti =1; I <= m; i++) if(Can[i]) printf ("%d\n", i); return 0;}
Equation of noip2014 Solution