Created
September 24, 2018 08:27
-
-
Save leira/a3cba2cb66f9f46c4b61daa228ac9b0e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN | |
| #include "doctest.h" | |
| using ll = long long; | |
| bool isPrime(ll n) | |
| { | |
| if (n == 1) return false; | |
| auto ub = std::sqrt(n); | |
| for (int i = 2; i <= ub; i += 1) { | |
| if ((n % i) == 0) return false; | |
| } | |
| return true; | |
| } | |
| TEST_CASE("Check primes") { | |
| for (ll i : {2, 3, 5, 7, 1117, 7639}) { | |
| CHECK(isPrime(i)); | |
| } | |
| for (ll i : {1, 4, 6, 9, 1118, 7631}) { | |
| CHECK_FALSE(isPrime(i)); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment