fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int a(int i, int j) {
  6. if( i == -1 && j == -1 )
  7. return -1;
  8. if( i == -1 || j == -1 )
  9. return 1;
  10. return 1 + a(i-1,j) + a(i-1,j-1);
  11. }
  12.  
  13. int main() {
  14.  
  15. int n; cin >> n;
  16. for(int i = 0; i < n; i++) {
  17. for(int j = 0; j < n; j++)
  18. cout << setw(4) << a(i,j) << " ";
  19. cout << "\n";
  20. }
  21. for(int i = 0; i < n; i++)
  22. cout << a(i,i) << ", ";
  23. cout << "\n";
  24. for(int i = 0; i < n/2; i++)
  25. cout << a(2*i+1,i) << ", ";
  26. cout << "\n";
  27.  
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 3300KB
stdin
10
stdout
   1    3    3    3    3    3    3    3    3    3 
   3    5    7    7    7    7    7    7    7    7 
   5    9   13   15   15   15   15   15   15   15 
   7   15   23   29   31   31   31   31   31   31 
   9   23   39   53   61   63   63   63   63   63 
  11   33   63   93  115  125  127  127  127  127 
  13   45   97  157  209  241  253  255  255  255 
  15   59  143  255  367  451  495  509  511  511 
  17   75  203  399  623  819  947 1005 1021 1023 
  19   93  279  603 1023 1443 1767 1953 2027 2045 
1, 5, 13, 29, 61, 125, 253, 509, 1021, 2045, 
3, 15, 63, 255, 1023,