diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/somme.cpp | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/cpp/somme.cpp b/cpp/somme.cpp index e42ad64..df8f8ee 100644 --- a/cpp/somme.cpp +++ b/cpp/somme.cpp @@ -6,22 +6,16 @@ output: 1 #include <iostream> #include <fstream> -bool pari(int n) -{ - return ((n % 2) == 0) ? true : false; -} +bool pari(int n) { return ((n % 2) == 0) ? true : false; } int sequenza(int n, bool pollatz, int tCollatz = -1) { - int m; + int m, tot = 1; if(pollatz) m = 5; else m = 3; - - int tot = 1; - while(n != 1) { if(pari(n)) @@ -29,12 +23,10 @@ int sequenza(int n, bool pollatz, int tCollatz = -1) else n = n*m+1; - tot++; if(tCollatz != -1 && tot > tCollatz) break; - } return tot; |