AcWing 3626. 三元一次方程
原题链接
简单
作者:
Hygen
,
2021-06-05 22:57:23
,
所有人可见
,
阅读 303
3626.三元一次方程
数据量比较小,用最简单的暴力做法加上几组特判即可。
#include <iostream>
using namespace std;
int main()
{
int T;
cin >> T;
while (T -- ){
int n;
cin >> n;
if(n == 2 || n == 4 || n == 1) {cout << "-1" << endl;continue;}
for (int i = 0; i <= n/3; i ++ ){
for (int j = 0; j <= n/5; j ++ ){
for (int k = 0; k <= n/7; k ++ ){
if(3*i + 5*j + 7*k == n){
cout << i << ' ' << j << ' ' << k << endl;
goto loop;
}
if(i == n/3 && j == n/5 && k == n/7) goto loop;
}
}
}
loop: continue;
}
return 0;
}