CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
constexpr bool isSquare(unsigned long long num, unsigned long long i) {
return !(num > 0 ? isSquare(num - i, i + 2) : num);
}
int main() {
std::cout << isSquare(4, 1) << std::endl; //works
std::cout << isSquare(9, 1) << std::endl; //works wrong
std::cout << isSquare(10, 1); //doesn't work at all
return 0;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run