my attemt using Monte Carlo, effective when the number is small, but will resulting in RE when dealing with larger numbers;
You can view the full, well-formatted C++ source code here on GitHub: https://github.com/yawnlento/yawnscodes/blob/main/P10002%E8%92%99%E5%A1%94%E5%8D%A1%E7%BD%97%E9%9A%8F%E6%9C%BA%E5%B0%9D%E8%AF%95.cpp;
suggestions :using DP will always be better.




