Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Konard/fc700b03f64b5c92c6fb56e53d6f8ca8 to your computer and use it in GitHub Desktop.
Save Konard/fc700b03f64b5c92c6fb56e53d6f8ca8 to your computer and use it in GitHub Desktop.
#include<iostream>
using namespace std;
int foo(int n)
{
if (n == 0)
{
return 3;
}
if (n == 1)
{
return 2;
}
else
{
return foo(n-1) * foo(n-2) - n;
}
}
int main()
{
int n = 0, n1 = 0, n2 = 0, res = 0;
cout << "cin n: ";
cin >> n;
if (n == 0)
{
n1 = 3;
}
if (n == 1)
{
n2 = 2;
}
int i = 0;
while (n > 1)
{
if (i >= n)
{
break;
}
res = n1 * n2 - i;
n1 = n2;
n2 = res;
i++;
}
cout << res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment