-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path(a+b)n.cpp
65 lines (57 loc) · 1.26 KB
/
(a+b)n.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
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <climits>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main()
{
while (true)
{
int n = 0;
cin >> n;
if (n == 0)
{
break;
}
vector<long long> a = {1, 1};
for (int i = 3; i <= n + 1; ++i)
{
vector<long long> temp = {1};
for (int j = 1; j <= i - 2; ++j)
{
temp.push_back(a[j - 1] + a[j]);
}
temp.push_back(1);
a = temp;
}
for (int i = 0; i <= n; ++i)
{
if (i == 0)
{
cout << a[i] << "a^" << n;
}
else
{
cout << " + ";
if (i == n)
{
cout << a[i] << "b^" << n;
}
else
{
cout << a[i] << "a^" << n - i << " * b^" << i;
}
}
}
cout << '\n';
}
return 0;
}