The function takes the parameter: n
(n is always strictly greater than 0) and returns an array or a string (depending on the language) of the form:
[(a, b), ...] or [[a, b], ...] or {{a, b}, ...} or or [{a, b}, ...]
with all (a, b)
which are the possible removed numbers in the sequence 1 to n
.
[(a, b), ...] or [[a, b], ...] or {{a, b}, ...} or ...
will be sorted in increasing order of the "a".
It happens that there are several possible (a, b). The function returns an empty array (or an empty string) if no possible numbers are found which will prove that my friend has not told the truth! (Go: in this case return nil
).
removNb(26) should return [(15, 21), (21, 15)]
or
removNb(26) should return { {15, 21}, {21, 15} }
or
removeNb(26) should return [[15, 21], [21, 15]]
or
removNb(26) should return [ {15, 21}, {21, 15} ]
or
removNb(26) should return "15 21, 21 15"
function removeNb (n) {
let a;
let b;
let result = [];
const gaus = sum(n);
for(a = 1; a<=n; a++) {
b = (gaus-a) / (a+1) ;
if(Number.isInteger(b) && b<=n) {
result.push([a,b]);
}
}
return result;
}
// sum function using reduce methodfunction sum(number) {
let array=[];
for(i = 1; i<=number ;i++) {
array.push(i);
}
const sums = array.reduce(function(acc,cur){
return acc+cur;
});
return sums;
}
function removeNb (n) {
// from the instruction:
// a * b = S(n) - a - b
// and the sum of all first n natural numbers is
// S(n) = n * (n + 1) / 2
// so we can refrase the first formula like this:
// a * b = n * (n + 1) / 2 - a - b
// a * b + b = n * (n + 1) / 2 - a
// b * (a + 1) = n * (n + 1) / 2 - a
// b = (n * (n + 1) / 2 - a) / (a + 1)
// but a and b are natural and up to n
var results = [];
for (var a = 1; a <= n; a++) {
var b = (n * (n + 1) / 2 - a) / (a + 1);
if (b % 1 === 0 && b <= n) results.push([a, b]);
}
return results;
}
유일한 차이점은 'sum(1~n)을 구할 때 어느 방식을 사용했느냐'이다.
Determining whether your friend is cheating can be a complex situation. It's important to approach it with caution and gather evidence before jumping to conclusions. Trust and open communication are key. I say you can visit https://www.yellowbirdproject.com/how-to-spy-on-someones-text-messages-without-their-phone-for-free/ and gain skills about girlfriend chat. If you suspect something, have an honest conversation with your friend, expressing your concerns and seeking clarification. Remember to maintain a non-accusatory tone, as misunderstandings can often arise in relationships.
The https://www.airslate.com/workflows/document/shopping Academy guides each of you and your colleagues through a comprehensive certification programme that teaches you all you need to know about constructing any sort of workflow online, configuring Bots, and simulating real-world use cases.