Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
50
Task/Arithmetic-numbers/JavaScript/arithmetic-numbers.js
Normal file
50
Task/Arithmetic-numbers/JavaScript/arithmetic-numbers.js
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// Arithmetic numbers
|
||||
|
||||
var n = 1;
|
||||
var arithmCnt = 0;
|
||||
var composCnt = 0;
|
||||
var outStr = new String();
|
||||
console.log("The first 100 arithmetic numbers are:");
|
||||
while (arithmCnt < 1000001) {
|
||||
let dv = 1;
|
||||
let dvCnt = 0;
|
||||
let sum = 0;
|
||||
while (true) {
|
||||
quot = Math.floor(n / dv);
|
||||
if (quot < dv)
|
||||
break;
|
||||
if (quot == dv && n % dv == 0) {
|
||||
// n is a square
|
||||
sum += quot;
|
||||
dvCnt++;
|
||||
break;
|
||||
}
|
||||
if (n % dv == 0) {
|
||||
sum += dv + quot;
|
||||
dvCnt += 2;
|
||||
}
|
||||
dv++;
|
||||
}
|
||||
if (sum % dvCnt == 0) {
|
||||
// n is arithmetic
|
||||
arithmCnt++;
|
||||
if (arithmCnt <= 100) {
|
||||
outStr += n.toString().padStart(4, ' ');
|
||||
if (arithmCnt % 10 == 0) {
|
||||
console.log(outStr);
|
||||
outStr = "";
|
||||
}
|
||||
}
|
||||
if (dvCnt > 2)
|
||||
composCnt++;
|
||||
if (arithmCnt == 1000 || arithmCnt == 10000 || arithmCnt == 100000 || arithmCnt == 1000000) {
|
||||
console.log(outStr);
|
||||
outStr = "The " + arithmCnt.toString().padStart(7, ' ') +
|
||||
"th arithmetic number is " + n.toString().padStart(8, ' ') +
|
||||
" up to which " + composCnt.toString().padStart(6, ' ') +
|
||||
" are composite.";
|
||||
}
|
||||
}
|
||||
n++;
|
||||
}
|
||||
console.log(outStr);
|
||||
Loading…
Add table
Add a link
Reference in a new issue