MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / is_square

Function is_square

code/tricks/is_square.cpp:4–12  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2void init_is_square() {
3 rep(i,0,64) M |= 1ULL << (63-(i*i)%64); }
4inline bool is_square(ll x) {
5 if (x == 0) return true; // XXX
6 if ((M << x) >= 0) return false;
7 int c = __builtin_ctz(x);
8 if (c & 1) return false;
9 x >>= c;
10 if ((x&7) - 1) return false;
11 ll r = sqrt(x);
12 return r*r == x; }
13// vim: cc=60 ts=2 sts=2 sw=2:

Callers 1

testFunction · 0.85

Calls 1

sqrtFunction · 0.85

Tested by 1

testFunction · 0.68