Sgu-255 Winsock 3 Beta

Source: Internet
Author: User

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;}
      
     
    
   
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.