答案:55,94,56
纯暴力,按照题意暴力枚举a,b,c的值。
如果a,b,c遍历到999大概需要15秒,遍历到99可以瞬间出来答案。
小技巧:根据题意可以大概猜到应该是100以内的两位数。
也可以用数学方法化简:点这里
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 505;
int n, m;
int gcd(int a, int b)
{
return b ? gcd(b, a % b) : a;
}
// 求组合数,返回分数形式的 pair
PII cnm(int n, int m)
{
PII res = { 1, 1};
for (int i = n; i >= n - m + 1; i--) {
res.first *= i;
}
if (m != 0) {
for (int i = m; i >= 1; i--) {
res.second *= i;
}
}
return res;
}
// 把分数化简为互质形式(即最简分数)
PII huaj(int a, int b)
{
int d = gcd(a, b);
return { a / d, b / d };
}
void solve()
{
for (int a = 1; a <= 99; a++) {
for (int b = 1; b <= 99; b++) {
for (int c = 1; c <= 99; c++) {
PII pb = cnm(a + b + c, 2);
int p12a = a * b;
int p23a = b * c;
int p13a = a * c;
// 分别求出分数形式的概率,分子分母用 pair 存储
PII p12 = huaj(a * b * pb.second, pb.first);
PII p23 = huaj(b * c * pb.second, pb.first);
PII p13 = huaj(a * c * pb.second, pb.first);
if (p12.first != 517) continue;
if (p12.second != 2091) continue;
if (p23.first != 2632) continue;
if (p23.second != 10455) continue;
if (p13.first != 308) continue;
if (p13.second != 2091) continue;
cout << a << "," << b << "," << c << "\n";
return;
}
}
}
cout << "请扩大范围" << endl;
}
int main()
{
solve();
return 0;
}