Codeforces 1515B - Phoenix and Puzzle Solution


 

Solution in C++: 

///******Bismillahir-Rahmanir-Rahim******///

///AH Tonmoy

///Department of CSE,23rd batch

    ///Islamic University,Bangladesh

    1. #include <bits/stdc++.h>
    2. using namespace std;
    3. map<long long,long long> mp;
    4. long long ans,t,n,i,v;
    5. int main()
    6. {
    7. mp[2]=1;
    8. mp[4]=1;
    9. ans=2,i=1;
    10. while(ans<=1e9)
    11. {
    12. v=(2*i)+1;
    13. v=v*2;
    14. ans+=v;
    15. mp[ans]=1;
    16. i++;
    17. }
    18. ans=4,i=1;
    19. while(ans<=1e9)
    20. {
    21. v=(2*i)+1;
    22. v=v*4;
    23. ans+=v;
    24. mp[ans]=1;
    25. i++;
    26. }
    27. ios::sync_with_stdio(false);
    28. cin.tie(0);
    29. cin>>t;
    30. while(t--)
    31. {
    32.  
    33. cin>>n;
    34. if(mp[n]==1)
    35. cout<<"YES"<<endl;
    36. else
    37. cout<<"NO"<<endl;
    38.  
    39. }
    40. return 0;
    41. }

    No comments

    Most View Post

    Recent post

    Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

      Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

    Powered by Blogger.