Euler #12


SUBMITTED BY: Guest

DATE: Jan. 24, 2014, 9:05 a.m.

FORMAT: Text only

SIZE: 601 Bytes

HITS: 957

  1. #include <iostream>
  2. using namespace std;
  3. bool countdiv500(int x);
  4. int main()
  5. {
  6. for(int i = 1; ;i++)
  7. {
  8. int tn = (i * (i + 1)) / 2;
  9. cout << "\n" << tn << " -- " << i;
  10. if(countdiv500(tn))
  11. {
  12. cout << "\nRequired number: " << tn;
  13. break;
  14. }
  15. }
  16. cout << "\n";
  17. return 0;
  18. }
  19. bool countdiv500(int x)
  20. {
  21. int count = 0, i = 1;
  22. while(i != x)
  23. {
  24. if(x % i == 0)
  25. {
  26. count++;
  27. }
  28. if(count == 500)
  29. {
  30. return 1;
  31. break;
  32. }
  33. i++;
  34. }
  35. return 0;
  36. }

comments powered by Disqus