5 kyu

Is my friend cheating?

491 of 18,458g964

Description:

  • A friend of mine takes the sequence of all numbers from 1 to n (where n > 0).
  • Within that sequence, he chooses two numbers, a and b.
  • He says that the product of a and b should be equal to the sum of all numbers in the sequence, excluding a and b.
  • Given a number n, could you tell me the numbers he excluded from the sequence?

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).

Examples:

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"

or

in C:
removNb(26) should return  {{15, 21}{21, 15}} tested by way of strings.
Function removNb should return a pointer to an allocated array of Pair pointers, each one also allocated. 

Note

See examples of returns for each language in "RUN SAMPLE TESTS"

Fundamentals
Mathematics
Puzzles

Stats:

CreatedMay 4, 2015
PublishedMay 5, 2015
Warriors Trained78030
Total Skips22218
Total Code Submissions133295
Total Times Completed18458
Python Completions6226
Ruby Completions491
C# Completions1105
Java Completions1998
Clojure Completions87
JavaScript Completions4178
Haskell Completions294
CoffeeScript Completions29
TypeScript Completions576
C++ Completions1364
Elixir Completions104
PHP Completions515
Crystal Completions13
F# Completions58
C Completions317
Rust Completions421
Swift Completions247
Go Completions463
R Completions66
Shell Completions33
OCaml Completions28
Fortran Completions10
Julia Completions46
Scala Completions165
PowerShell Completions27
Nim Completions12
Racket Completions22
Reason Completions3
Kotlin Completions216
Prolog Completions13
Pascal Completions7
Factor Completions10
Raku Completions5
Perl Completions16
Elm Completions4
COBOL Completions9
D Completions6
Erlang Completions10
Total Stars1852
% of votes with a positive feedback rating89% of 2158
Total "Very Satisfied" Votes1757
Total "Somewhat Satisfied" Votes312
Total "Not Satisfied" Votes89
Ad
Contributors
  • g964 Avatar
  • jhoffner Avatar
  • Abbe Avatar
  • Blind4Basics Avatar
  • wneumann Avatar
  • Voile Avatar
  • rxe Avatar
  • Bubbler Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • 4500zenja1 Avatar
Ad