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));
}
}
ReferenceError: gcb is not defined at gcd (solution.js:13:9) at solution (solution.js:6:13) at solutionWrapper (/tmp/exec.js:396:28) at Promise.resolve.then (/tmp/exec.js:422:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
// 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) {
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));
}
}
10 4 4 2
// 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;
}
// 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;
}
// 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 % 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;
}
// 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;
}
NaN undefined
// 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;
}
solution.js:11 console.log(array[i%N) ^ SyntaxError: Unexpected token ) at createScript (vm.js:80:10) at Object.runInNewContext (vm.js:135:10) at getSolution (/tmp/exec.js:386:29) at Promise.resolve.then (/tmp/exec.js:420:34) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
// 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;
}
[ true, true, true, true, true, true, true, true, true, true, true ] 0 true
// 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;
}
[ true, true, true, true, true, true, true, true, true, true, true ]
// 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;
}
[10, 1]
[ true, true, true, true, true, true, true, true, true, true, true ]
function result: 10
[ true, true, true, true, true, true, true, true, true, true, true ]
// 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;
}
[10, 1]
[10, 3]
[ true, true, true, true, true, true, true, true, true, true, true ]
function result: 10
[ true, true, true, true, true, true, true, true, true, true, true ]
function result: 10
[ true, true, true, true, true, true, true, true, true, true, true ]
// 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;
}
[10, 1]
[10, 10]
[ true, true, true, true, true, true, true, true, true, true, true ]
function result: 10
[ true, true, true, true, true, true, true, true, true, true, true ]
function result: 1
[ true, true, true, true, true, true, true, true, true, true, true ]
// 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;
}
[10, 1]
[10, 10]
[ true, true, true, true, true, true, true, true, true, true ]
function result: 10
[ true, true, true, true, true, true, true, true, true, true ]
function result: 1
[ true, true, true, true, true, true, true, true, true, true ]
// 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;
}
[10, 1]
[10, 10]
[ true, true, true, true, true, true, true, true, true, true ]
function result: 10
[ true, true, true, true, true, true, true, true, true, true ]
function result: 1
[ true, true, true, true, true, true, true, true, true, true ]
// 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;
}
[10, 1]
[10, 10]
[1000000000, 1]
[ true, true, true, true, true, true, true, true, true, true ]
function result: 10
[ true, true, true, true, true, true, true, true, true, true ]
function result: 1
[ true, true, true, true, true, true, true, true, true, true ]
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 1: node::Abort() [/opt/lang/nodejs/bin/node] 2: 0x128059c [/opt/lang/nodejs/bin/node] 3: v8::Utils::ReportOOMFailure(char const*, bool) [/opt/lang/nodejs/bin/node] 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/opt/lang/nodejs/bin/node] 5: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [/opt/lang/nodejs/bin/node] 6: v8::internal::HashTable<v8::internal::SeededNumberDictionary, v8::internal::SeededNumberDictionaryShape>::NewInternal(v8::internal::Isolate*, int, v8::internal::PretenureFlag) [/opt/lang/nodejs/bin/node] 7: v8::internal::HashTable<v8::internal::SeededNumberDictionary, v8::internal::SeededNumberDictionaryShape>::New(v8::internal::Isolate*, int, v8::internal::PretenureFlag, v8::internal::MinimumCapacity) [/opt/lang/nodejs/bin/node] 8: v8::internal::HashTable<v8::internal::SeededNumberDictionary, v8::internal::SeededNumberDictionaryShape>::EnsureCapacity(v8::internal::Handle<v8::internal::SeededNumberDictionary>, int, v8::internal::PretenureFlag) [/opt/lang/nodejs/bin/node] 9: v8::internal::Dictionary<v8::internal::SeededNumberDictionary, v8::internal::SeededNumberDictionaryShape>::Add(v8::internal::Handle<v8::internal::SeededNumberDictionary>, unsigned int, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyDetails, int*) [/opt/lang/nodejs/bin/node] 10: 0xe0adcc [/opt/lang/nodejs/bin/node] 11: v8::internal::JSObject::AddDataElement(v8::internal::Handle<v8::internal::JSObject>, unsigned int, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::ShouldThrow) [/opt/lang/nodejs/bin/node] 12: v8::internal::Object::AddDataProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::ShouldThrow, v8::internal::Object::StoreFromKeyed) [/opt/lang/nodejs/bin/node] 13: v8::internal::JSObject::DefineOwnPropertyIgnoreAttributes(v8::internal::Lookustdout:
<--- Last few GCs ---> [3:0x230ca60] 1191 ms: Mark-sweep 100.0 (106.9) -> 100.0 (106.9) MB, 47.6 / 0.0 ms allocation failure GC in old space requested [3:0x230ca60] 1234 ms: Mark-sweep 100.0 (106.9) -> 100.0 (103.9) MB, 43.1 / 0.0 ms last resort GC in old space requested [3:0x230ca60] 1277 ms: Mark-sweep 100.0 (103.9) -> 100.0 (103.9) MB, 43.2 / 0.0 ms last resort GC in old space requested <--- JS stacktrace ---> ==== JS stack trace ========================================= Security context: 0x708f9325ee1 <JSObject> 2: from [native array.js:1] [bytecode=0x16a0834f3411 offset=528](this=0x16a0834cd881 <JSFunction Array (sfi = 0x63c549a7809)>,arrayLike=0x63c549cdf39 <Object map = 0x214f85e49a01>,mapfn=0x63c549cdef1 <JSFunction Array.from (sfi = 0x16a0834f27b9)>,receiver=0x63c54982311 <undefined>) 3: arguments adaptor frame: 2->3 5: solution [solution.js:6] [bytecode=0x16a0834f28e9 offset=30](this=0x...
// 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);
}
}
[10, 1]
[10, 10]
[1000000000, 1]
function result: 10
function result: 1
10 10 1
function result: 1000000000
// 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);
}
}
[10, 1]
[10, 10]
[1000000000, 1]
function result: 10
function result: 1
10 10 1
function result: 1000000000
// 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);
}
}
[10, 1]
[10, 10]
[1000000000, 1]
function result: 10
function result: 1
10 10 1
function result: 1000000000
// 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);
}
}
[10, 1]
[10, 10]
[1000000000, 1]
function result: 10
function result: 1
10 10 1
function result: 1000000000
// 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);
}
}
[10, 1]
[10, 10]
[1000000000, 1]
function result: 10
function result: 1
function result: 1000000000
// 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);
}
}
[10, 1]
[10, 10]
[1000000000, 1]
function result: 10
function result: 1
function result: 1000000000
// 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 solution obtained perfect score.