fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. unsigned long n,digit_sum(unsigned long);
  7. bool isSquare(unsigned long),isCube(unsigned long);
  8. for(n=100000;n<500000;n++)
  9. {
  10. if(digit_sum(n)==43)
  11. {
  12. if(isSquare(n) && !isCube(n))
  13. {
  14. cout<<n;
  15. return 0;
  16. }
  17. if(!isSquare(n) && isCube(n))
  18. {
  19. cout<<n;
  20. return 0;
  21. }
  22. }
  23. }
  24. for(n=500000;n<1000000;n++)
  25. {
  26. if(digit_sum(n)==43)
  27. {
  28. if(isSquare(n) && isCube(n))
  29. {
  30. cout<<n;
  31. return 0;
  32. }
  33. }
  34. }
  35. return 0;
  36. }
  37. bool isSquare(unsigned long x)
  38. {
  39. return (sqrt(x)-long(sqrt(x))==0) ? true : false;
  40. }
  41. bool isCube(unsigned long x)
  42. {
  43. return (cbrt(x)-long(cbrt(x))==0) ? true : false;
  44. }
  45. unsigned long digit_sum(unsigned long x)
  46. {
  47. unsigned long ret=0;
  48. while(x>=1)
  49. {
  50. ret+=(x%10);
  51. x/=10;
  52. }
  53. return ret;
  54. }
Success #stdin #stdout 0.01s 3460KB
stdin
Standard input is empty
stdout
499849