#include
using namespace std;
int main() {
int n, y;
cout << "n = ";<br> cin >> n;
cout << "y = ";<br> cin >> y;
int a[11][6];
int n3, n5;
cout << "---------------------------------------\n";<br> a[0][0] = n;
for (int i=0; i n = a[i][0];
n5 = n / 5;
n3 = 0;
while (n3*3+n5*5 != n) {
if ((n-n5*5) % 3 == 0)
n3 = (n-n5*5) / 3;
else n5 = n5-1;
}
a[i][1] = n3; a[i][2] = n5;
a[i][3] = a[i][1]*5+a[i][2]*9;
if ((i==0)||(i==1)) a[i][4] = 0;
else if (i==2) a[i][4] = a[0][0];
else a[i][4] = a[i-3][3];
a[i][5] = a[i][0]+a[i][3]-a[i][4];
a[i+1][0] = a[i][5];
}
for (int i=0; i cout << i+1 << " ";<br> for (int j=0; j<6; j++) { <br> cout.width(8);
cout << a[i][j] << " ";<br> }
cout << endl;<br> }
return 0;
}
Пример:
n = 9
y = 10
---------------------------------------
1 9 3 0 15 0 24
2 24 3 3 42 0 66
3 66 2 12 118 9 175
4 175 0 35 315 15 475
5 475 0 95 855 42 1288
6 1288 1 257 2318 118 3488
7 3488 1 697 6278 315 9451
8 9451 2 1889 17011 855 25607
9 25607 4 5119 46091 2318 69380
10 69380 0 13876 124884 6278 187986