-
Notifications
You must be signed in to change notification settings - Fork 1
/
Twitter_240324_2.cpp
50 lines (39 loc) · 1.07 KB
/
Twitter_240324_2.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <boost/rational.hpp> // for boost::rational
#include <cstdint> // for std::int32_t
#include <iostream> // for std::cout, std::endl
#include <numeric> // for std::gcd
#include <vector> // for std::vector
namespace {
using myfraction = boost::rational<std::int32_t>;
using myvector = std::vector<myfraction>;
static auto const MAX = myfraction(3, 8);
static auto const MIN = myfraction(3, 11);
myvector get_answer();
} // namespace
int main()
{
auto const answer = get_answer();
for (auto const & item : answer) {
std::cout << item << ", ";
}
std::cout << "\nanswer = " << answer.size() << std::endl;
}
namespace {
myvector get_answer()
{
myvector answer;
for (auto i = 1;; i++) {
if (std::gcd(8, i) != 1) {
continue;
}
auto fraction = myfraction(8, i);
if (fraction <= MIN) {
break;
}
if (fraction > MIN && fraction < MAX) {
answer.push_back(fraction);
}
}
return answer;
}
} // namespace