A. solving equations
The second limitation is easy to find quite useless, subtract directly on the line.
For the first limit, it can not be done directly found, given the inclusion-exclusion. Set $ f_s $ represents the number of $ s $ scheme does not meet the set limits, just about inclusion and exclusion:
$$ans=\sum\limits-1^{|s|}*f_s$$
Can be found, in fact, is a $ $ F_S number of combinations can be obtained using a paddle method, it was found not guarantee modulus is prime, exLucas can be directly calculated.
B. cosmic sequence
Easily found, the subject is given in equation or a convolution exclusive, I have not found , so: $ a_i = a_ {i- 1} * a_1 $.
Or convolutional vary to meet the binding rate, thus: $ a_ {2 * i} = a_i * a_i $.
Multiplying this request and then directly things, optimization can be done with fwt $ O (2 ^ n * n * p) $.
Since then XOR convolution has some beautiful nature, so you can position corresponding point values are added, and finally unified IDFT back is correct.
Then converted into the original problem so that: the number of a given number of $ x $, for each $ x $, obtains $ \ sum \ limits_ {i = 0} ^ {p} x ^ {2 ^ {i}} $.
This problem modulus is very small, only 10,007 kinds of base number, consider pre-violence.
Consider multiplier, so $ f_ {x, i} = \ sum \ limits_ {j = 0} ^ {2 ^ {i} -1} x ^ {2 ^ {j}} $, metastasis:
$$f_{x,i}=f_{x,i-1}+f_{x^{2^{2^{i-1}}},i-1}$$
So violence against all $ x $ doubling pre-out array, for $ a_1 $ calculated after multiplying DFT IDFT and then go back to.
Optimization can be done plus $ O (n * 2 ^ n + mod * logmod) $.
C. exp
No, not read.