Collecting magical berries
No optimisation so far but a few comments to make your code easier to read/improve :

1 Don't do "using namespace std;"

2 Give your variables meaningful names.

3 Declare your variables in the smallest possible scope. Also, you should declare and define in the same times when it's possible. That would make things much easier (such as int res = nChoosek(r,re); instead of res*=nChoosek(r,re);).

4 Be consistent. You use for(i=0;i&lt;re;i++) {foo;} and then, a few lines later i=0; while((r-re-i) &gt; 1){foo; i++;}. Using another for loop would have have been a better option : for (i=0; i&lt;r-re-1; i++) {foo;}

5 Enable the warnings in your compiler. A few weird things such as the useless statement in for(i-0;i&lt;n;i++) should be detected.

6 Add a comment about the algorithm you've used.

Once this is done, we'll be in better conditions to start thinking about optimisations.