文章
232
粉丝
165
获赞
377
访问
118.7k
#include <stdio.h>
int main() {
int n;
// 输入n (n<1000)
scanf("%d", &n);
// 第一步:找到最大的、能被7整除的总和 target_total
int max_total = 3 * n;
int target_total = 0;
for (int total = max_total; total >= 0; total--) {
if (total % 7 == 0) {
target_total = total;
break;
}
}
// 第二步:遍历a、b,计算c,筛选满足所有条件的组合
for (int a = 0; a <= n; a++) {
for (int b = 0; b <= n; b++) {
int c = target_total - a - b;
// 判断c的范围 + 核心条件
if (c >= 0 && c <= n) {
if ((a + b) % 3 == 0 && (b + c) % 5 == 0) {
printf("%d %d %d\n", a, b, c);
}
}
}
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发