summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-02-13 15:18:28 -0700
committerJack Sangdahl <[email protected]>2025-02-13 15:18:28 -0700
commitd5c06c689e3328546cd4c486b30a7909651501ed (patch)
tree0b2dc1900cc8a3f4da4e376fc24e5e6fc0c0b367
parent19bb82f44e8da0ab854f93248a8fe72d430b46e4 (diff)
downloadcses-d5c06c689e3328546cd4c486b30a7909651501ed.tar.gz
cses-d5c06c689e3328546cd4c486b30a7909651501ed.zip
1618. trailing zeors
-rw-r--r--introductory_problems/readme.md7
-rw-r--r--introductory_problems/trailing_zeros.cpp13
2 files changed, 20 insertions, 0 deletions
diff --git a/introductory_problems/readme.md b/introductory_problems/readme.md
index 0550440..4490312 100644
--- a/introductory_problems/readme.md
+++ b/introductory_problems/readme.md
@@ -62,3 +62,10 @@ Your task is to calculate the number of bit strings of length `n`. For example,
**Input**: The only input line has an integer `n`. (Example: 3)
**Output**: Print the result modulo 10E9 + 7. (Example: 8)
+
+### Trailing Zeros
+Your task is to calculate the number of trailing zeros in the factorial `n!`. For example, `20! = 20!=2432902008176640000` and it has 4 trailing zeros.
+
+**Input**: The only input line has an integer `n`. (Example: 20)
+
+**Output**: Print the number of in `n!`. (Example: 4)
diff --git a/introductory_problems/trailing_zeros.cpp b/introductory_problems/trailing_zeros.cpp
new file mode 100644
index 0000000..02fff6f
--- /dev/null
+++ b/introductory_problems/trailing_zeros.cpp
@@ -0,0 +1,13 @@
+// 1618. Trailing Zeros
+#include <bits/stdc++.h>
+using namespace std;
+
+int main() {
+ static int n, ans;
+ scanf("%d", &n);
+ while (n) {
+ n /= 5;
+ ans += n;
+ }
+ printf("%d\n", ans);
+}