Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Amicable-pairs/ReScript/amicable-pairs.re
Normal file
25
Task/Amicable-pairs/ReScript/amicable-pairs.re
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
let isqrt = (v) => {
|
||||
Belt.Float.toInt(
|
||||
sqrt(Belt.Int.toFloat(v)))
|
||||
}
|
||||
|
||||
let sum_divs = (n) => {
|
||||
let sum = ref(1)
|
||||
for d in 2 to isqrt(n) {
|
||||
if mod(n, d) == 0 {
|
||||
sum.contents = sum.contents + (n / d + d)
|
||||
}
|
||||
}
|
||||
sum.contents
|
||||
}
|
||||
|
||||
{
|
||||
for n in 2 to 20000 {
|
||||
let m = sum_divs(n)
|
||||
if (m > n) {
|
||||
if sum_divs(m) == n {
|
||||
Printf.printf("%d %d\n", n, m)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue