-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
07.15: prime number, integer(수 나누기 게임)
- Loading branch information
1 parent
ccaf748
commit 4c46b21
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 수 나누기 게임 : 소수, 에라토스테네스의 체, 정수론 | ||
const input = require("fs") | ||
.readFileSync("/dev/stdin") | ||
.toString() | ||
.trim() | ||
.split("\n") | ||
.map((v) => v.split(" ").map((v) => Number(v))); | ||
const [n] = input.shift(); | ||
const cards = input.shift(); | ||
const biggest = cards | ||
.slice() | ||
.sort((a, b) => a - b) | ||
.at(-1); | ||
const count = new Array(biggest + 1).fill(0); | ||
const isValid = new Array(biggest + 1).fill(null); | ||
const answer = []; | ||
|
||
for (const number of cards) { | ||
const yaksu = []; | ||
const sqrt = Math.sqrt(number); | ||
for (let i = 1; i <= sqrt; i++) { | ||
if (number % i === 0) { | ||
yaksu.push(i); | ||
count[i]++; | ||
|
||
if (number / i !== i) { | ||
yaksu.push(number / i); | ||
count[number / i]++; | ||
} | ||
} | ||
} | ||
isValid[number] = yaksu; | ||
} | ||
|
||
for (let i = 0; i < cards.length; i++) { | ||
const number = cards[i]; | ||
const yaksus = isValid[number].sort((a, b) => a - b); | ||
|
||
let cnt = 0; | ||
for (const yaksu of yaksus) { | ||
if (isValid[yaksu]) { | ||
cnt++; | ||
} | ||
} | ||
answer.push(count[number] - cnt); | ||
} | ||
|
||
console.log(answer.join(" ")); |