1515B - Phoenix and Puzzle - CodeForces Solution


brute force geometry math number theory *1000

Please click on ads to support us..

Python Code:

for i in range (int(input())):
    n = int(input())
    if ((n/2)**0.5).is_integer() or ((n/4)**0.5).is_integer():
        print('YES')
    else:
        print('NO')

C++ Code:

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <numeric>
typedef long long int ll;
// Geometry 


//typedef std::complex<double> point; 
//#define X real()
//#define Y imag()
//#define angle(a)                (atan2((a).imag(), (a).real()))
//#define vec(a,b)                ((b)-(a))
//#define same(p1,p2)             (dp(vec(p1,p2),vec(p1,p2)) < EPS)
//#define dp(a,b)                 ( (conj(a)*(b)).real() )	// a*b cos(T), if zero -> prep
//#define cp(a,b)                 ( (conj(a)*(b)).imag() )	// a*b sin(T), if zero -> parllel
//#define length(a)               (hypot((a).imag(), (a).real()))
//#define normalize(a)            (a)/length(a)
//#define polar(r,ang)            ((r)*exp(point(0,ang)))  ==> Already added in c++11
//#define rotateO(p,ang)          ((p)*exp(point(0,ang)))
//#define rotateA(p,ang,about)  (rotateO(vec(about,p),ang)+about)
//#define reflectO(v,m)  (conj((v)/(m))*(m))



// end of Geometry


// debuging 
#define fast ios::sync_with_stdio(false) ,  cin.tie(NULL); 
#define debug(x) cout << #x << "=" << x << endl
#define debug2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define debug3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define show(a) cout << "vector " << #a << " : " << endl ; for(auto e : a) cout << e << " " 
#define endl '\n' 
#define sz(x) (int)x.size()
// end of debuging

#endif
using namespace std;


//point reflect(point p, point p0, point p1) {
//    point z = p-p0, w = p1-p0;
//    return conj(z/w)*w + p0; // Refelect point p1 around p0p1
//}
// 
// 
//bool isCollinear(point a, point b, point c) {	
//	return fabs( cp(b-a, c-a) ) < EPS;	
//} 
// 
//bool isPointOnRay(point p0, point p1, point p2) {
//    if(length(p2-p0) < EPS) return true;
//    return same( normalize(p1-p0), normalize(p2-p0) );
//}
// 
//bool isPointOnSegment(point a, point b, point c) {
//	return isPointOnRay(a, b, c) || isPointOnRay(b, a, c);
//}
// 
// 
//double distToLine( point p0, point p1, point p2 ) {
//	return fabs(cp(p1-p0, p2-p0)/length(p0-p1)); // area = 0.5*b*h
//}
// 
//

//double distToSegment( point p0, point p1, point p2 ) {
//	double d1, d2;
//	point v1 = p1-p0, v2 = p2-p0;
//	if( (d1 = dp(v1, v2) ) <= 0)	return length(p2-p0);
//	if( (d2 = dp(v1, v1) ) <= d1)	return length(p2-p1);
//	double t = d1/d2;
//	return length(p2 - (p0 + v1*t) );
//}


//const int N=1e5+5, M=1e3+5, MOD=1e9+7,OO=0x3f3f3f3f;
//const ll LOO=0x3f3f3f3f3f3f3f3f;
//const long double EPS=1e-20;

// file input / output 
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
bool check(ll n ){

      ll  f = sqrt((double)n);
      return (f * f == n) ; 
}
bool ok(){
     ll n ; cin >> n ; 
     if((!(n % 2) && check(n / 2) ) || ((n % 4 == 0) && check(n / 4)) ) return true ;    
     return false ; 
}
void taste_case(){
     cout << (ok() ? "YES" : "NO") << endl ; 
}
       
int main(){
    fast ;
    int tt  = 1;
    cin >> tt ;
    
    while(tt--){
            taste_case(); 
    }
    return 0 ;
}


Comments

Submit
0 Comments
More Questions

760B - Frodo and pillows
1006A - Adjacent Replacements
1195C - Basketball Exercise
1206A - Choose Two Numbers
1438B - Valerii Against Everyone
822A - I'm bored with life
9A - Die Roll
1430B - Barrels
279B - Books
1374B - Multiply by 2 divide by 6
1093B - Letters Rearranging
1213C - Book Reading
1468C - Berpizza
1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel
1647D - Madoka and the Best School in Russia
1208A - XORinacci
1539B - Love Song
22B - Bargaining Table
1490B - Balanced Remainders
264A - Escape from Stones
1506A - Strange Table
456A - Laptops
855B - Marvolo Gaunt's Ring
1454A - Special Permutation
1359A - Berland Poker
459A - Pashmak and Garden
1327B - Princesses and Princes