Jump to content

Category talk:Wren-math: Difference between revisions

→‎Source code: Added Int.totient mehod.
m (→‎Source code: Now uses Wren S/H lexer.)
(→‎Source code: Added Int.totient mehod.)
Line 656:
}
return ans + 1
}
 
// Returns how many positive integers up to 'n' are relatively prime to 'n'.
static totient(n) {
if (n < 1) return 0
var tot = n
var i = 2
while (i*i <= n) {
if (n%i == 0) {
while (n%i == 0) n = (n/i).floor
tot = tot - (tot/i).floor
}
if (i == 2) i = 1
i = i + 2
}
if (n > 1) tot = tot - (tot/n).floor
return tot
}
 
9,479

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.