fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. int countAns(int n)
  5. {
  6. int p[] = {1,2,3,4,5,6,7,8,9};
  7. int count = 0;
  8. do {
  9. if (p[1]%p[2] || p[6]*p[7]%p[8]) continue;
  10. if (p[0] + 13*p[1]/p[2] + p[3] + 12*p[4] - p[5] + p[6]*p[7]/p[8] == n)
  11. ++count;
  12. } while (std::next_permutation(p, p+9));
  13. return count;
  14. }
  15.  
  16. void printAns(int n)
  17. {
  18. int p[] = {1,2,3,4,5,6,7,8,9};
  19. do {
  20. if (p[1]%p[2] || p[6]*p[7]%p[8]) continue;
  21. if (p[0] + 13*p[1]/p[2] + p[3] + 12*p[4] - p[5] + p[6]*p[7]/p[8] == n) {
  22. for (int i = 0; i < 9; ++i)
  23. std::cout << p[i] << " ";
  24. std::cout << "\n";
  25. }
  26. } while (std::next_permutation(p, p+9));
  27. }
  28.  
  29. int main()
  30. {
  31. /*for (int n=0; n < 500; ++n)
  32. {
  33. int count = countAns(n+21);
  34. if (count < 22 && count > 0)
  35. std::cout << n << " " << count << "\n";
  36. }*/
  37. printAns(19+21);
  38. }
  39.  
  40. /*
  41. 19 4
  42. 21 12
  43. 23 8
  44. 24 12
  45. 25 16
  46. 27 12
  47. 28 12
  48. 30 8
  49. 31 12
  50. 32 12
  51. 34 16
  52. 36 12
  53. 44 16
  54. 66 20
  55. 205 20
  56. 209 20
  57. 210 16
  58. 211 8
  59. 212 16
  60. 213 16
  61. 214 12
  62. 215 8
  63. 216 4
  64. 217 4
  65. 218 4
  66. 219 4
  67. */
  68.  
Success #stdin #stdout 0.01s 3096KB
stdin
Standard input is empty
stdout
2 8 4 5 1 7 3 6 9 
2 8 4 5 1 7 6 3 9 
5 8 4 2 1 7 3 6 9 
5 8 4 2 1 7 6 3 9