-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTSETP.cpp
217 lines (200 loc) · 6.04 KB
/
TSETP.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <map>
#include <string>
#include <vector>
using namespace std;
ifstream fin("TSETP.in");
ofstream fout("TSETP.out");
void solve1()
{
double temp1, temp2;
fin >> temp1 >> temp2;
int start = round(temp1 * 100), end = round(temp2 * 100);
fout << fixed << setprecision(2);
for (int nowNum = start; nowNum <= end; nowNum += 1)
{
for (int c = nowNum / 3; c <= nowNum; ++c)
{
for (int b = (nowNum - c) / 2 + 1; b <= c; ++b)
{
int a = nowNum - b - c;
if (nowNum * 10000 == a * b * c)
{
fout << nowNum / 100.0 << " = " << a / 100.0 << " + " << b / 100.0 << " + " << c / 100.0 << " = " << a / 100.0 << " * " << b / 100.0 << " * " << c / 100.0 << "\n";
//c = nowNum + 1;
//break;
}
}
}
}
}
double r(double a)
{
return round(a * 100) / 100;
}
void solve2()
{
double start, end;
fin >> start >> end;
fout << fixed << setprecision(2);
for (double nowNum = start; nowNum <= end; nowNum += 0.01)
{
for (double a = 0.01; a <= nowNum / 3; a += 0.01)
{
for (double b = a; b <= nowNum; b += 0.01)
{
double c = (nowNum / a) / b;
double a2 = r(a);
double b2 = r(b);
double c2 = r(c);
double nowNum2 = r(nowNum);
if (a2 + b2 + c2 == a2 * b2 * c2 && a2 * b2 * c2 == nowNum2 && b2 <= c2)
{
fout << nowNum2 << " = " << a2 << " + " << b2 << " + " << c2 << " = " << a2 << " * " << b2 << " * " << c2 << "\n";
}
if (a2 * b2 * c2 == nowNum && a2 + b2 + c2 == nowNum )
{
if (nowNum2 == 5.85)
{
fout << "BAD:" << nowNum2 << " = " << a2 << " + " << b2 << " + " << c2 << " = " << a2 << " * " << b2 << " * " << c2 << "\n";
}
}
}
}
}
}
void solve3()
{
double temp1, temp2;
fin >> temp1 >> temp2;
int start = round(temp1 * 100), end = round(temp2 * 100);
fout << fixed << setprecision(2);
for (int nowNum = start; nowNum <= end; ++nowNum)
{
for (int a = 1; a <= nowNum / 3; ++a)
{
for (int b = a; b <= nowNum / 2; ++b)
{
int c = nowNum * 10000 / (a * b);
if ((a + b + c) * 10000 == a * b * c && a + b + c == nowNum && b <= c)
{
fout << nowNum / 100.0 << " = " << a / 100.0 << " + " << b / 100.0 << " + " << c / 100.0 << " = " << a / 100.0 << " * " << b / 100.0 << " * " << c / 100.0 << "\n";
}
}
}
}
}
void solve4()
{
double temp1, temp2;
fin >> temp1 >> temp2;
int start = round(temp1 * 100), end = round(temp2 * 100);
fout << fixed << setprecision(2);
for (int nowNum = start; nowNum <= end; ++nowNum)
{
int nowNumBig=nowNum*1e4;
for (int a = 1; a * a * a <= nowNumBig; ++a)
{
for (int b = a; a * b * b <= nowNumBig; ++b)
{
int c = nowNumBig / (a * b);
if(b > c)
{
break;
}
if ((a + b + c) * 1e4 == a * b * c && a + b + c == nowNum)
{
fout << nowNum / 100.0 << " = " << a / 100.0 << " + " << b / 100.0 << " + " << c / 100.0 << " = " << a / 100.0 << " * " << b / 100.0 << " * " << c / 100.0 << "\n";
}
}
}
}
}
void solve5()
{
struct nums
{
int a;
int b;
int c;
int sum() const
{
return a + b + c;
}
bool operator < (const nums &temp) const
{
if (sum() != temp.sum())
{
return sum() < temp.sum();
}
else if (a != temp.a)
{
return a < temp.a;
}
else if (b != temp.b)
{
return b < temp.b;
}
else
{
return c < temp.c;
}
}
};
vector<nums> out;
for (int a = 1; 3 * a <= 25599; ++a)
{
for (int b = a; a + 2 * b <= 25599; ++b)
{
if (a * b == 10000)
{
continue;
}
if ((10000 * (a + b) % (a * b - 10000)) != 0)
{
continue;
}
int c = (10000 * (a + b)) / (a * b - 10000);
if (c >= b)
{
nums temp{a, b, c};
out.push_back(temp);
//fout << (a + b + c) / 100.0 << " = " << a / 100.0 << " + " << b / 100.0 << " + " << c / 100.0 << " = " << a / 100.0 << " * " << b / 100.0 << " * " << c / 100.0 << "\n";
}
}
}
sort(out.begin(), out.end());
while (true)
{
double temp1, temp2;
fin >> temp1 >> temp2;
if (fin.eof() == true)
{
break;
}
int start = round(temp1 * 100), end = round(temp2 * 100);
fout << fixed << setprecision(2);
int size = out.size();
for (int i = 0; i <= size - 1; ++i)
{
int a = out[i].a;
int b = out[i].b;
int c = out[i].c;
if (a + b + c >= start && a + b + c <= end)
{
fout << (a + b + c) / 100.0 << " = " << a / 100.0 << " + " << b / 100.0 << " + " << c / 100.0 << " = " << a / 100.0 << " * " << b / 100.0 << " * " << c / 100.0 << "\n";
}
}
}
}
int main()
{
solve5();
return 0;
}