Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,5 @@
|
|||
for (var dpa=[1,0,0], n=2; n<=20000; n+=1) {
|
||||
for (var ds=0, d=1, e=n/2+1; d<e; d+=1) if (n%d==0) ds+=d
|
||||
dpa[ds<n ? 0 : ds==n ? 1 : 2]+=1
|
||||
}
|
||||
document.write('Deficient:',dpa[0], ', Perfect:',dpa[1], ', Abundant:',dpa[2], '<br>' )
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
for (var dpa=[1,0,0], n=2; n<=20000; n+=1) {
|
||||
for (var ds=1, d=2, e=Math.sqrt(n); d<e; d+=1) if (n%d==0) ds+=d+n/d
|
||||
if (n%e==0) ds+=e
|
||||
dpa[ds<n ? 0 : ds==n ? 1 : 2]+=1
|
||||
}
|
||||
document.write('Deficient:',dpa[0], ', Perfect:',dpa[1], ', Abundant:',dpa[2], '<br>' )
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
function primes(t) {
|
||||
var ps = {2:true, 3:true}
|
||||
next: for (var n=5, i=2; n<=t; n+=i, i=6-i) {
|
||||
var s = Math.sqrt( n )
|
||||
for ( var p in ps ) {
|
||||
if ( p > s ) break
|
||||
if ( n % p ) continue
|
||||
continue next
|
||||
}
|
||||
ps[n] = true
|
||||
}
|
||||
return ps
|
||||
}
|
||||
|
||||
function factorize(f, t) {
|
||||
var cs = {}, ps = primes(t)
|
||||
for (var n=f; n<=t; n++) if (!ps[n]) cs[n] = factors(n)
|
||||
return cs
|
||||
function factors(n) {
|
||||
for ( var p in ps ) if ( n % p == 0 ) break
|
||||
var ts = {}
|
||||
ts[p] = 1
|
||||
if ( ps[n /= p] ) {
|
||||
if ( !ts[n]++ ) ts[n]=1
|
||||
}
|
||||
else {
|
||||
var fs = cs[n]
|
||||
if ( !fs ) fs = cs[n] = factors(n)
|
||||
for ( var e in fs ) ts[e] = fs[e] + (e==p)
|
||||
}
|
||||
return ts
|
||||
}
|
||||
}
|
||||
|
||||
function pContrib(p, e) {
|
||||
for (var pc=1, n=1, i=1; i<=e; i+=1) pc+=n*=p;
|
||||
return pc
|
||||
}
|
||||
|
||||
for (var dpa=[1,0,0], t=20000, cs=factorize(2,t), n=2; n<=t; n+=1) {
|
||||
var ds=1, fs=cs[n]
|
||||
if (fs) {
|
||||
for (var p in fs) ds *= pContrib(p, fs[p])
|
||||
ds -= n
|
||||
}
|
||||
dpa[ds<n ? 0 : ds==n ? 1 : 2]+=1
|
||||
}
|
||||
document.write('Deficient:',dpa[0], ', Perfect:',dpa[1], ', Abundant:',dpa[2], '<br>' )
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
(() => {
|
||||
'use strict';
|
||||
|
||||
const
|
||||
// divisors :: (Integral a) => a -> [a]
|
||||
divisors = n => range(1, Math.floor(n / 2))
|
||||
.filter(x => n % x === 0),
|
||||
|
||||
// classOf :: (Integral a) => a -> Ordering
|
||||
classOf = n => compare(divisors(n)
|
||||
.reduce((a, b) => a + b, 0), n),
|
||||
|
||||
classTypes = {
|
||||
deficient: -1,
|
||||
perfect: 0,
|
||||
abundant: 1
|
||||
};
|
||||
|
||||
// GENERIC FUNCTIONS
|
||||
const
|
||||
// compare :: Ord a => a -> a -> Ordering
|
||||
compare = (a, b) =>
|
||||
a < b ? -1 : (a > b ? 1 : 0),
|
||||
|
||||
// range :: Int -> Int -> [Int]
|
||||
range = (m, n) =>
|
||||
Array.from({
|
||||
length: Math.floor(n - m) + 1
|
||||
}, (_, i) => m + i);
|
||||
|
||||
// TEST
|
||||
|
||||
// classes :: [Ordering]
|
||||
const classes = range(1, 20000)
|
||||
.map(classOf);
|
||||
|
||||
return Object.keys(classTypes)
|
||||
.map(k => k + ": " + classes
|
||||
.filter(x => x === classTypes[k])
|
||||
.length.toString())
|
||||
.join('\n');
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue