fork download
  1. /*
  2. Description: Using Brute-force Strategy to Search a Solution
  3.  
  4. 今有物不知其数,三三数之剩二,五五数之剩 三,七七数之剩二,问物几何?
  5. x = 2 (mod 3)
  6. x = 3 (mod 5)
  7. x = 2 (mod 7)
  8.  
  9. Author: Liutong Xu
  10. Date: 2016/10/25
  11. */
  12.  
  13. #include <stdio.h>
  14. #define LIMIT 100
  15. int main()
  16. {
  17. int x;
  18.  
  19. x = 1;
  20. while (!(x % 3 == 2 && x % 5 == 3 && x % 7 == 2)) //while not a solution
  21. x++;
  22. printf("x = %d\n",x);
  23.  
  24. //if you wang to find all solutions
  25. //for (x = 1;x < LIMIT;x++)
  26. // if (x % 3 == 2 && x % 5 == 3 && x % 7 == 2)
  27. // printf("x = %d\n",x);
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
x = 23