-
Notifications
You must be signed in to change notification settings - Fork 0
/
492.go
51 lines (45 loc) · 890 Bytes
/
492.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
# ------------------------------ #
# #
# version 0.0.1 #
# #
# Aleksiej Ostrowski, 2023 #
# #
# https://aleksiej.com #
# #
# ------------------------------ #
*/
package main
import (
"fmt"
"math"
)
func constructRectangle(area int) []int {
min_1_d_2 := area
length := area
width := 1
cand1 := 0
margin := int(math.Ceil(math.Sqrt(float64(area))))
for {
cand1 += 1
if cand1 > margin {
break
}
if area%cand1 != 0 {
continue
}
cand2 := area / cand1
if cand2 >= cand1 {
if (cand2 - cand1) < min_1_d_2 {
length = cand2
width = cand1
}
}
}
return []int{length, width}
}
func main() {
fmt.Println(constructRectangle(1))
// fmt.Println(constructRectangle(122122))
fmt.Println("ok")
}