fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. // this is a program to find the first triangular number that is divisible by 500 factors
  6.  
  7. int main()
  8. {
  9. long long int b = 0; // limit for triangular num (1+2+3+......+b)
  10. long long int d; // divisor
  11. long long int t = 0; // triangular number in use
  12. long long int r = 0; // root of current test number
  13. int f = 0; // factor counter
  14.  
  15. while (f <= 500)
  16. {
  17. f = 0;
  18.  
  19. // next triangular number
  20. t += ++b;
  21.  
  22. // get closest root.
  23. r = floor(sqrt(t));
  24.  
  25. // counts factors
  26. for( d = 1 ; d < r; ++d )
  27. {
  28. if( t % d == 0 )
  29. f += 2;
  30. }
  31. if (t % r == 0)
  32. ++f;
  33. }
  34.  
  35. printf("%lld is the first triangular number with more than 500 factors\n", t);
  36. return 0;
  37. }
Success #stdin #stdout 1.71s 2248KB
stdin
Standard input is empty
stdout
76576500 is the first triangular number with more than 500 factors