Two positive integers N and M are given. Integer N represents the number of chocolates arranged in a circle, numbered from 0 to N − 1.
You start to eat the chocolates. After eating a chocolate you leave only a wrapper.
You begin with eating chocolate number 0. Then you omit the next M − 1 chocolates or wrappers on the circle, and eat the following one.
More precisely, if you ate chocolate number X, then you will next eat the chocolate with number (X + M) modulo N (remainder of division).
You stop eating when you encounter an empty wrapper.
For example, given integers N = 10 and M = 4. You will eat the following chocolates: 0, 4, 8, 2, 6.
The goal is to count the number of chocolates that you will eat, following the above rules.
Write a function:
function solution(N, M);
that, given two positive integers N and M, returns the number of chocolates that you will eat.
For example, given integers N = 10 and M = 4. the function should return 5, as explained above.
Write an efficient algorithm for the following assumptions:
- N and M are integers within the range [1..1,000,000,000].
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
return (gcd(N, M, 1))
}
function gcd(a, b, count) {
if (a % b === 0) {
return count;
} else {
return (gcb())
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
return (gcd(N, M, 1))
}
function gcd(a, b, count) {
if (a % b === 0) {
return count;
} else {
return (gcb(b, a % b))
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
return (gcd(N, M, 1))
}
function gcd(a, b, count) {
if (a % b === 0) {
return count;
} else {
return (gcb(b, a % b, count++))
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
return (gcd(N, M, 1))
}
function gcd(a, b, count) {
if (a % b === 0) {
return count;
} else {
return (gcb(b, a % b, ++count));
}
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
return (gcd(N, M, 1))
}
function gcd(a, b, count) {
if (a % b === 0) {
return count;
} else {
return (gcd(b, a % b, ++count));
}
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
return (gcd(N, M, 1))
}
function gcd(a, b, count) {
if (a % b === 0) {
return count;
} else {
return (gcd(b, a % b, ++count));
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
return (gcd(N, M, 1))
}
function gcd(a, b, count) {
console.log(a, b);
if (a % b === 0) {
return count;
} else {
return (gcd(b, a % b, ++count));
}
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, (v,i) => false);
let i = 0;
while (array[i] === true) {
array[i] = false;
i += M;
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, (v,i) => false);
let i = 0;
while (array[i] === true) {
array[i %N.length] = false;
i += M;
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, (v,i) => false);
let i = 0;
let count = 0;
while (array[i] === true) {
array[i % N.length] = false;
i += M;
count++;
}
return count;
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, (v,i) => tr);
let i = 0;
let count = 0;
while (array[i] === true) {
array[i % N.length] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
let i = 0;
let count = 0;
while (array[i] === true) {
array[i % N.length] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
let i = 0;
let count = 0;
while (array[i] === true) {
array[i % N.length] = false;
i += M;
count++;
}
return count;
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
let i = 0;
let count = 0;
while (array[i] === true) {
array[i % N.length] = false;
i += M;
count++;
}
return count;
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
let i = 0;
let count = 0;
while (array[i % N.length] === true) {
array[i % N.length] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
let i = 0;
let count = 0;
while (array[i % N.length] === true) {
array[i % N.length] = false;
i += M;
count++;
}
return count;
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
let i = 0;
let count = 0;
while (array[i % N.length] === true) {
array[i % N.length] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
let i = 0;
let count = 0;
console.log(i%N.length)
console.log(array(i%N.length))
while (array[i % N.length] === true) {
array[i % N.length] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
let i = 0;
let count = 0;
console.log(i%N.length)
console.log(array[i%N.length])
while (array[i % N.length] === true) {
array[i % N.length] = false;
i += M;
count++;
}
return count;
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
console.log(array)
let i = 0;
let count = 0;
console.log(i%N.length)
console.log(array[i%N.length])
while (array[i % N.length] === true) {
array[i % N.length] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
console.log(array)
let i = 0;
let count = 0;
console.log(i%N)
console.log(array[i%N)
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
console.log(array)
let i = 0;
let count = 0;
console.log(i%N)
console.log(array[i%N])
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
console.log(array)
let i = 0;
let count = 0;
console.log(i%N)
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+1}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N+}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
let array = Array.from({length: N}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1)
let array = Array.from({length: N}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M=== 1)
let array = Array.from({length: N}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N
}
let array = Array.from({length: N}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
let array = Array.from({length: N}, () => true);
console.log(array)
let i = 0;
let count = 0;
while (array[i % N] === true) {
array[i % N] = false;
i += M;
count++;
}
return count;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
return count;
}
function gcd(a, b) {
if(a % b === 0) {
return
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
return count;
}
function gcd(a, b) {
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
return count;
}
function gcd(a, b) {
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
return count;
}
function gcd(a, b) {
console.log()
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
return count;
}
function gcd(a, b) {
console.log(gcd)
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
return count;
}
function gcd(a, b) {
console.log(a)
console.log(b)
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
return N / gcd(N, M);
}
function gcd(a, b) {
console.log(a)
console.log(b)
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
let value
console.log()
return N / gcd(N, M);
}
function gcd(a, b) {
console.log(a)
console.log(b)
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
let value = N / gcd(N, M)
console.log(value)
return value;
}
function gcd(a, b) {
console.log(a)
console.log(b)
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
let value = N / gcd(N, M)
console.log(value)
return value;
}
function gcd(a, b) {
console.log(a)
console.log(b)
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
let value = N / gcd(N, M)
console.log(value)
return value;
}
function gcd(a, b) {
console.log(a)
console.log(b)
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
let value = N / gcd(N, M)
console.log(value)
return value;
}
function gcd(a, b) {
console.log(a)
console.log(b)
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
let value = N / gcd(N, M)
console.log(value)
return value;
}
function gcd(a, b) {
console.log(a)
console.log(b)
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
let value = N / gcd(N, M)
console.log(value)
return value;
}
function gcd(a, b) {
console.log(a)
console.log(b)
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
let value = N / gcd(N, M)
console.log(value)
return value;
}
function gcd(a, b) {
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
return N / gcd(N, M);
}
function gcd(a, b) {
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
return N / gcd(N, M);
}
function gcd(a, b) {
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
The submission is being evaluated.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, M) {
// write your code in JavaScript (Node.js 8.9.4)
if (N === 1) {
return 1;
}
if (M === 1) {
return N;
}
return N / gcd(N, M);
}
function gcd(a, b) {
if(a % b === 0) {
return b;
} else {
return gcd(b, a % b);
}
}
The submission is being evaluated.