Codeforces 1515B - Phoenix and Puzzle Solution
Solution in C++:
///******Bismillahir-Rahmanir-Rahim******///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
- #include <bits/stdc++.h>
- using namespace std;
- map<long long,long long> mp;
- long long ans,t,n,i,v;
- int main()
- {
- mp[2]=1;
- mp[4]=1;
- ans=2,i=1;
- while(ans<=1e9)
- {
- v=(2*i)+1;
- v=v*2;
- ans+=v;
- mp[ans]=1;
- i++;
- }
- ans=4,i=1;
- while(ans<=1e9)
- {
- v=(2*i)+1;
- v=v*4;
- ans+=v;
- mp[ans]=1;
- i++;
- }
- ios::sync_with_stdio(false);
- cin.tie(0);
- cin>>t;
- while(t--)
- {
- cin>>n;
- if(mp[n]==1)
- cout<<"YES"<<endl;
- else
- cout<<"NO"<<endl;
- }
- return 0;
- }
No comments