Created
October 9, 2016 16:38
-
-
Save jangsoopark/2c776017db034056dd27dc1b16f2a02f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
inline bool isOdd(int num) | |
{ | |
return num & 0x01; | |
} | |
inline bool numberCheck(int num1, int num2) | |
{ | |
if (isOdd(num1) & isOdd(num2)) | |
return true; | |
else if ((!isOdd(num1) & !isOdd(num2))) | |
return true; | |
else | |
return false; | |
} | |
int function(int x) | |
{ | |
int boundary = 1; | |
int seq; | |
auto sequence = [] (int n) -> int { | |
return (((n - 1) * n) >> 1) + n; | |
}; | |
while (true) | |
{ | |
seq = sequence(boundary); | |
if (x <= seq && numberCheck(x, seq)) | |
break; | |
else | |
boundary++; | |
} | |
return boundary; | |
} | |
int main(void) | |
{ | |
std::cout << function(12) << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment