PROBLEM 32
Easy

Divisible by 3

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#32

Print `YES` if integer `n` is divisible by 3, otherwise `NO`.

EXAMPLE

Example

Input
18
Output
YES

LIMITS

Constraints

All numeric input values fit in JavaScript `Number`.
📖
LEARN Theory for this problem
+

### Divisible by 3

`if / else if / else` chooses a branch from boolean conditions. Comparisons such as `<`, `>=`, `===` and logical operators `&&`, `||`, `!` combine the exact rules that decide which output is valid.

💡
NEED HELP? Hints
+

['Translate every case from the statement into a boolean condition before writing branches.', 'Mentally substitute at least one value for each branch and verify that exactly the intended branch runs.']

ANSWER Solution
+
const fs = require('fs');

const n = Number(fs.readFileSync(0, 'utf8').trim());
const divisible = n % 3 === 0;

console.log(divisible ? 'YES' : 'NO');