1. 程式人生 > >NOIP2014解方程

NOIP2014解方程

 

 

哦最開始還以為是個什麼難題,哦原來是秦九韶,哦我不會秦九韶

哦我們把x往外提一下,哦!這複雜度怎麼就O(nm)了啊!

哦好事,這題已經是A了,哎woc怎麼一直WA啊!

哦原來讀入的數最大為10^1000,哦我快讀沒取模,哦好事

哦已經是A了

考驗選手的亂搞能力

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 #define uint unsigne int
 4 #define ull unsigned long long
 5 using namespace std;
 6 const
ll mod = 19260817; 7 const int maxn = 500010; 8 const int maxm = 1000010; 9 ll a[maxn]; 10 ll n, m; 11 ll ans[maxn], tot = 0; 12 bool flag = 0; 13 14 inline ll read() { 15 ll x = 0, y = 1; 16 char ch = getchar(); 17 while(!isdigit(ch)) { 18 if(ch == '-') y = -1; 19 ch = getchar();
20 } 21 while(isdigit(ch)) { 22 x = ((x << 1) % mod + (x << 3) % mod + ch - '0') % mod; 23 ch = getchar(); 24 } 25 return x * y; 26 } 27 28 inline bool check(ll x) { 29 ll sum = 0; 30 for(register ll i = n; i >= 1; --i) 31 sum = ((sum + a[i]) * x) % mod;
32 sum = (sum + a[0]) % mod; 33 return !sum; 34 } 35 36 int main() { 37 n = read(), m = read(); 38 for(register ll i = 0; i <= n; ++i) a[i] = read(); 39 for(register ll i = 1; i <= m; ++i) 40 if(check(i)) { 41 flag = 1; 42 ans[++tot] = i; 43 } 44 printf("%lld\n", tot); 45 for(register ll i = 1; i <= tot; ++i) 46 printf("%lld\n", ans[i]); 47 return 0; 48 }