NOIP2014解方程

 

 

哦最開始還覺得是個什麼難題,哦原來是秦九韶,哦我不會秦九韶c++

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

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

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

哦已是A了code

考驗選手的亂搞能力blog

 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 }
相關文章
相關標籤/搜索