This question focuses on understanding the derivation formula. f (n) = f (n-1) + 6 * (n-1) is simplified to: f (n) = 3 * n * (n-1) + 2. When a triangle is added, each change will intersection the two sides of the first triangle, so that two small triangles are added, that is, two sides. F (2) = 3*2 + f (1), and then add a triangle. Each side will intersection the four sides of the first two triangles to form four small triangles, f (3) = 3*4 + f (2), and so on, that is, f (n) = 3*2 * (n-1) + f (n-1 ).
The Code is as follows:
[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <cstdlib>
# Include <cmath>
# Include <cstring>
# Include <string>
# Include <vector>
# Include <list>
# Include <deque>
# Include <queue>
# Include <iterator>
# Include <stack>
# Include <map>
# Include <set>
# Include <algorithm>
# Include <cctype>
Using namespace std;
Const int n= 10001;
Typedef long LL;
Int main ()
{
Int I, j, t, T, n;
Cin> T;
While (T --)
{
Scanf ("% d", & n );
Cout <3 * n * (n-1) + 2 <endl;
}
Return 0;
}
# Include <iostream>
# Include <cstdio>
# Include <cstdlib>
# Include <cmath>
# Include <cstring>
# Include <string>
# Include <vector>
# Include <list>
# Include <deque>
# Include <queue>
# Include <iterator>
# Include <stack>
# Include <map>
# Include <set>
# Include <algorithm>
# Include <cctype>
Using namespace std;
Const int n= 10001;
Typedef long LL;
Int main ()
{
Int I, j, t, T, n;
Cin> T;
While (T --)
{
Scanf ("% d", & n );
Cout <3 * n * (n-1) + 2 <endl;
}
Return 0;
}