Last active
August 29, 2015 14:27
-
-
Save cengiz-io/917ef8d934c201d63982 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
#include <iostream> | |
using namespace std; | |
struct measure { | |
template<typename F, typename ...Args> | |
static void execution(F func, Args&&... args) { | |
auto start = chrono::system_clock::now(); | |
func(forward<Args>(args)...); | |
auto duration = chrono::system_clock::now() - start; | |
cout << "Elapsed: " << duration.count() / 1000 << "ms" << endl; | |
} | |
}; | |
bool isDivisibleBy1To20(long n) { | |
if (n % 20 != 0) { | |
return 0; | |
} | |
for (int i = 11; i <= 20; i++) { | |
if (n % i != 0) { | |
return 0; | |
} | |
} | |
return 1; | |
} | |
int main() { | |
long x = 1; | |
measure::execution([&x]() { | |
while (x++) { | |
if (isDivisibleBy1To20(x)) { | |
cout << "Number is " << x << endl; | |
break; | |
} | |
} | |
}); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment