@@ -227,15 +227,15 @@ <h2>Editor</h2>
227227}
228228
229229function eulerTotient ( n ) {
230- const seq = [ ] ;
231- for ( let i = 1 ; i <= n ; i ++ ) {
232- let count = 0 ;
233- for ( let j = 1 ; j <= i ; j ++ ) {
234- if ( gcd ( i , j ) === 1 ) count ++ ;
235- }
236- seq . push ( count ) ;
230+ const seq = [ ] ;
231+ for ( let i = 1 ; i <= n ; i ++ ) {
232+ let count = 0 ;
233+ for ( let j = 1 ; j <= i ; j ++ ) {
234+ if ( gcd ( i , j ) === 1 ) count ++ ;
237235 }
238- return seq ;
236+ seq . push ( count ) ;
237+ }
238+ return seq ;
239239}
240240
241241function binomial ( n , k ) {
@@ -426,7 +426,9 @@ <h2>Editor</h2>
426426}
427427
428428function count ( arr ) {
429- const max = Math . max ( ...arr ) ;
429+ if ( ! arr . length ) return [ ] ;
430+ const max = arr . reduce ( ( m , x ) => ( x > m ? x : m ) , - Infinity ) ;
431+ if ( ! Number . isFinite ( max ) ) throw new Error ( 'max is not finite' ) ;
430432 const sorted = [ ...arr ] . sort ( ( a , b ) => a - b ) ;
431433 const result = [ ] ;
432434 let countv = 0 ;
@@ -441,6 +443,27 @@ <h2>Editor</h2>
441443 return result ;
442444}
443445
446+ function acount ( countArr ) {
447+ if ( ! countArr . length ) return [ ] ;
448+ const result = [ ] ;
449+ for ( let i = 0 ; i < countArr . length ; i ++ ) {
450+ const prev = i === 0 ? 0 : countArr [ i - 1 ] ;
451+ const freq = countArr [ i ] - prev ;
452+ for ( let k = 0 ; k < freq ; k ++ ) {
453+ result . push ( i ) ;
454+ }
455+ }
456+ return result ;
457+ }
458+
459+ function toarray ( f , n = 200000 , start = 0 ) {
460+ const result = [ ] ;
461+ for ( let i = 0 ; i < n ; i ++ ) {
462+ result . push ( f ( start + i ) ) ;
463+ }
464+ return result ;
465+ }
466+
444467function li ( x ) {
445468 if ( x < 2 ) return 0 ;
446469 const a = 2 ;
0 commit comments