Sgu-255 Winsock 3 Beta
Question:
Given a function F (x) = g (x + 1) + g (x + 2) +... + g (x? 2) , Where G (x) = [the binary representation of x has only 3 1] . Here you are. N (N <= 100) Input, each input is for you M (m <= 231? 1) , You need to find F (x) = whether m has a unique integer solution , Output exists YES Otherwise, output NO .
Solution:
First, consider the Function F (x) Monotonicity, F (x + 1 )? F (x) = g (x? 2 + 2) + g (x? 2 + 1 )? G (x + 1) , From G (x) From the beginning, there are: G (x) = g (x? 2) . So F (x + 1 )? F (x) = g (x? 2 + 1) So we can find that F (x) It is monotonous. If F (x0) = m Is the only answer, it must satisfy F (x0 + 1 )? F (x0) = 1, f (x0 )? F (x0? 1) = 1? G (x0? 2 + 1) = g (x0? 2? 1) = 1 . Then we observe and find that G (x0? 2? 1) = 1 Required X0 In binary format, it must be ... 10 And it is also satisfied G (x0? 2 + 1) = 1 .
So X0 = 2 t + 2 + 2 (t> = 0) And then we will discuss and find F (2 t + 2 + 2) = (t + 22) + 1 So what we need to do is F (2 t + 2 + 2) = (t + 22) + 1 = m whether there is a non-negative integer solution .
This is a good practice. I will not repeat it again.
AC code:
#include
#include
#include
#include
#include
#include #define sqr(a) ((a)*(a))using namespace std;const double eps=1e-8;int n;int main(){ scanf("%d",&n); for(;n>0;n--) { long long m; scanf("%lld",&m); if(m<=1) { puts("NO"); continue; } long long a=1,b=3,c=-2*m+4; long long delta=sqr(b)-4*a*c; long long haha=(long long)(sqrt(delta)+eps); if(sqr(haha)==delta) puts("YES"); else puts("NO"); } return 0;}