fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Table
  5. {
  6. int digit2;
  7. int digit10;
  8. int prev;
  9. int n;
  10. };
  11. int main() {
  12. int usedtable[10000];
  13. Table table[10000];
  14. int i;
  15. int target = 2439;
  16. int now, end;
  17. for(i = 0 ; i < 10000 ; i++)
  18. {
  19. usedtable[i] = 0;
  20. }
  21. now = 0; end = 1;
  22. table[0].n = 0;
  23. while(end > now)
  24. {
  25. for(i = 0 ; i < 10 ; i++)
  26. {
  27. if((table[now].n + target * i) % 10 < 2)
  28. {
  29. int nextnum = (table[now].n + target * i);
  30. if(nextnum == 1)
  31. {
  32. int n = now;
  33. cout << target << " *" << endl;
  34. cout << 0;
  35. while(n)
  36. {
  37. cout << table[n].digit10;
  38. n = table[n].prev;
  39. }
  40. cout << " =" << endl;
  41. n = now;
  42. cout << 1;
  43. while(n)
  44. {
  45. cout << table[n].digit2;
  46. n = table[n].prev;
  47. }
  48. cout<<endl;
  49. }
  50. if(usedtable[nextnum / 10]) continue;
  51. usedtable[nextnum / 10] = 1;
  52. table[end].n = nextnum / 10;
  53. table[end].digit2 = nextnum % 10;
  54. table[end].digit10 = i;
  55. table[end].prev = now;
  56. end++;
  57. }
  58. }
  59. now++;
  60. }
  61. return 0;
  62. }
Success #stdin #stdout 0s 3212KB
stdin
Standard input is empty
stdout
2439 *
00004100496519520340344449 =
10001111011110110100111111