链接:https://ac.nowcoder.com/acm/problem/16499
来源:牛客网
第一行输出方程在[1, m]内的整数解的个数。
接下来每行一个整数,按照从小到大的顺序依次输出方程在[1, m]内的一个整数解。
2 10 1 -2 1
1 1
2 10 2 -3 1
2 1 2
2 10 1 3 2
0
对于30%的数据,0<n>i|≤100,an≠0,m≤100;
对于50%的数据,0<n>i|≤10100,an≠0,m≤100;
对于70%的数据,0<n>i|≤1010000,an≠0,m≤10000;
对于100%的数据,0<n>i|≤1010000,an≠0,m≤1000000。
至于什么是秦九韶算法,百度上有比较详细的解释。
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <string> 5 #include <cstring> 6 #include <cstdlib> 7 #include <cmath> 8 #include <stack> 9 #include <queue> 10 #include <set> 11 #include <map> 12 #include <vector> 13 #include <ctime> 14 #include <cctype> 15 #include <bitset> 16 #include <utility> 17 #include <sstream> 18 #include <complex> 19 #include <iomanip> 20 #define inf 0x3f3f3f3f 21 typedef long long ll; 22 using namespace std; 23 #define mod 1000000007 24 using namespace std; 25 int n,m,a[110],ct,jg[1000010]; 26 ll read() 27 { 28 ll sum=0; 29 char str; 30 int fg=1; 31 while(str=getchar(),!((str>=‘0‘&&str<=‘9‘)||str==‘-‘)); 32 do 33 { 34 if(str==‘-‘) 35 { 36 fg=-1; 37 continue; 38 } 39 sum=sum*10+str-‘0‘; 40 sum%=mod; 41 } 42 while((str=getchar(),(str>=‘0‘&&str<=‘9‘)||str==‘-‘)); 43 return fg*sum; 44 } 45 void print(ll x) 46 { 47 if(!x) 48 return; 49 print(x/10); 50 putchar(x%10+‘0‘); 51 } 52 bool pd(ll x) 53 { 54 ll sum=0; 55 for(int i=n; i>=1; i--) 56 { 57 sum=(sum+a[i])*x; 58 sum%=mod; 59 } 60 sum+=a[0]; 61 sum%=mod; 62 return !sum; 63 } 64 int main() 65 { 66 ios::sync_with_stdio(false); 67 n=read(); 68 m=read(); 69 for(int i=0; i<=n; i++) 70 a[i]=read(); 71 for(int i=1; i<=m; i++) 72 if(pd(i)) 73 jg[++ct]=i; 74 cout<<ct<<endl; 75 for(int i=1; i<=ct; i++) 76 { 77 print(jg[i]); 78 printf("\n"); 79 } 80 return 0; 81 }
原文:https://www.cnblogs.com/mxnzqh/p/11834344.html