Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 54eb30d

Browse files
author
openset
committed
Add: Preimage Size of Factorial Zeroes Function
1 parent c7e3bb2 commit 54eb30d

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
package preimage_size_of_factorial_zeroes_function
1+
package problem_793
2+
3+
func preimageSizeFZF(K int) int {
4+
l, r := 0, 5*(K+1)
5+
for l <= r {
6+
m := l + (r-l)/2
7+
km := zeros(m)
8+
if km < K {
9+
l = m + 1
10+
} else if km > K {
11+
r = m - 1
12+
} else {
13+
return 5
14+
}
15+
}
16+
return 0
17+
}
18+
19+
func zeros(x int) int {
20+
r := 0
21+
for x > 0 {
22+
r += x / 5
23+
x /= 5
24+
}
25+
return r
26+
}
Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
package preimage_size_of_factorial_zeroes_function
1+
package problem_793
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
input int
7+
expected int
8+
}
9+
10+
func TestPreimageSizeFZF(t *testing.T) {
11+
tests := [...]caseType{
12+
{
13+
input: 0,
14+
expected: 5,
15+
},
16+
{
17+
input: 5,
18+
expected: 0,
19+
},
20+
{
21+
input: 17,
22+
expected: 0,
23+
},
24+
{
25+
input: 11,
26+
expected: 0,
27+
},
28+
}
29+
for _, tc := range tests {
30+
output := preimageSizeFZF(tc.input)
31+
if output != tc.expected {
32+
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
33+
}
34+
}
35+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /