Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Last active November 5, 2019 08:37
Show Gist options
  • Save pinglunliao/23eb86971d1655449e09 to your computer and use it in GitHub Desktop.
Save pinglunliao/23eb86971d1655449e09 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
using namespace std;
int numD( short n )
{
if( n <= 3 )
return pow(2.0, n);
else
{
int k = n - 1;
int c = (k * k + k + 2)/2;
n = n -1;
return numD(n) + c;
}
}
int main()
{
int n;
int d;
while( cin >> n )
{
d = numD(n);
cout << d << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment