Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let n = +gets();
- let sequence = [];
- let primes = [];
- let output = [];
- for (i = 1; i < n + 1; i++) {
- sequence.push(i);
- }
- for (i = 0; i < sequence.length; i++) {
- if (isPrime(sequence[i])) {
- primes.push(sequence[i]);
- }
- }
- for (i = 0; i < primes[primes.length - 1]; i++) {
- if (isPrime(sequence[i])) {
- output.push('1');
- print(output.join(''));
- } else {
- output.push('0');
- }
- }
- function isPrime (num) {
- if (num === 1) {
- return true;
- } else if (num <= 3) {
- return true;
- } else if (num % 2 === 0 || num % 3 === 0) {
- return false;
- }
- let j = 5;
- while(j*j <= num) {
- if (num % j === 0 || num % (j+2) === 0) {
- return false;
- }
- j += 6;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment