fork download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. unsigned long long happy(unsigned int n, unsigned int base)
  7. {
  8. if (n%2 || n < 2 || base < 2) throw runtime_error("Wrong data");
  9. auto N = [](unsigned int n, unsigned int k,
  10. unsigned int base, auto&&N)
  11. {
  12. if (n == 1) return (unsigned long long)(k < base);
  13. unsigned long long s = 0;
  14. for(unsigned int l = 0; l < base; ++l) s += N(n-1,k-l,base,N);
  15. return s;
  16. };
  17. unsigned long long s = 0;
  18. for(unsigned int k = 0; k <= (base-1)*n/2; ++k)
  19. {
  20. auto m = N(n/2,k,base,N);
  21. s += m*m;
  22. }
  23. return s;
  24. }
  25.  
  26. int main(int argc, char * argv[])
  27. {
  28. cout << 13*happy(12,13) << endl;
  29. }
  30.  
Success #stdin #stdout 0.05s 5620KB
stdin
Standard input is empty
stdout
9203637295151