diff options
author | InigoGutierrez <inigogf.95@gmail.com> | 2020-06-01 21:22:36 +0200 |
---|---|---|
committer | InigoGutierrez <inigogf.95@gmail.com> | 2020-06-01 21:22:36 +0200 |
commit | 10f157f42e9b08cd538c552735664da735f89f1a (patch) | |
tree | a4bdf03d05f0421be2592039db9e7de72198b09a | |
parent | 771882a2c87084613b64c4622caa53dfc2deede1 (diff) | |
download | AceptaElReto-10f157f42e9b08cd538c552735664da735f89f1a.tar.gz AceptaElReto-10f157f42e9b08cd538c552735664da735f89f1a.zip |
192, Por 3 o más 5, superando tiempo máximo.
-rw-r--r-- | c/192_por3oMas5.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/c/192_por3oMas5.cpp b/c/192_por3oMas5.cpp new file mode 100644 index 0000000..d8e3455 --- /dev/null +++ b/c/192_por3oMas5.cpp @@ -0,0 +1,39 @@ +#include <iostream> + +int sumN = 5; +int mulN = 3; + +int solve(int input) { + + int result = 0; + + if (input == 1) { + return 1; + } + + if (input > 0 && input % mulN == 0) { + result = solve(input / mulN); + } + + if (!result) { + if (input > sumN) { + result = solve(input - sumN); + } + } + + return result; + +} + +int main() { + int input; + std::cin >> input; + while (input != 0) { + if (solve(input)) + std::cout << "SI\n"; + else + std::cout << "NO\n"; + std::cin >> input; + } + return 0; +} |