571, 209 11, 4 提示 可使用long long int對付GNU C++,使用__int64對付VC6
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define limit 34
void f(long long x, long long &a, long long &b)
{
a += 3 * x;
b += x;
}
void g(long long x, long long &a, long long &b)
{
a += 2 * x;
b += x;
}
long long a[limit];
long long b[limit];
int main()
{
int n;
a[0] = 1;
b[0] = 0;
for (int i = 1; i < limit; i++)
{
f(a[i - 1], a[i], b[i]);
g(b[i-1], a[i], b[i]);
}
while (true)
{
cin >> n;
if (n == -1)
break;
cout << a[n] <<", "<<b[n]<< endl;
}
return 0;
}