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 925 (Div. 3) 1931D. Divisible Pairs Solution

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

    Powered by Blogger.