-
Notifications
You must be signed in to change notification settings - Fork 14
/
GCD.cpp
34 lines (30 loc) · 872 Bytes
/
GCD.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (c) 2013 Elements of Programming Interviews. All rights reserved.
#include <iostream>
#include <cassert>
#include <limits>
#include <random>
#include "./GCD.h"
using std::cout;
using std::default_random_engine;
using std::endl;
using std::numeric_limits;
using std::random_device;
using std::uniform_int_distribution;
int main(int argc, char *argv[]) {
long long x = 18, y = 12;
assert(GCD(x, y) == 6);
if (argc == 3) {
x = atoll(argv[1]), y = atoll(argv[2]);
cout << GCD(x, y) << endl;
assert(GCD(x, y) == another_GCD(x, y));
} else {
default_random_engine gen((random_device())());
for (int times = 0; times < 1000; ++times) {
uniform_int_distribution<long long>
dis(1, numeric_limits<long long>::max());
x = dis(gen), y = dis(gen);
assert(GCD(x, y) == another_GCD(x, y));
}
}
return 0;
}