7 kyu

Relatively Prime Numbers

893 of 1,634Nmistrata

Description:

Two numbers are relatively prime if their greatest common factor is 1; in other words: they cannot be divided by any other common numbers than 1.

13, 16, 9, 5, and 119 are all relatively prime because they share no common factors, except for 1. To see this, I will show their factorizations:

 13: 13
 16: 2 * 2 * 2 * 2
  9: 3 * 3
  5: 5
119: 17 * 7

Complete the function that takes 2 arguments: a number (n), and a list of numbers (arr). The function should return a list of all the numbers in arr that are relatively prime to n. All numbers will be positive integers.

Examples

n = 8
arr = [1, 2, 3, 4, 5, 6, 7]
>> [1, 3, 5, 7]

n = 15
arr = [72, 27, 32, 61, 77, 11, 40]
>> [32, 61, 77, 11]

n = 210
arr = [15, 100, 2222222, 6, 4, 12369, 99]
>> []
Fundamentals
Algorithms

Stats:

CreatedFeb 2, 2016
PublishedFeb 2, 2016
Warriors Trained3663
Total Skips81
Total Code Submissions5641
Total Times Completed1634
Python Completions893
Haskell Completions128
JavaScript Completions366
C++ Completions241
Crystal Completions10
Ruby Completions59
Prolog Completions6
C Completions24
Lua Completions10
Total Stars48
% of votes with a positive feedback rating87% of 301
Total "Very Satisfied" Votes237
Total "Somewhat Satisfied" Votes50
Total "Not Satisfied" Votes14
Ad
Contributors
  • Nmistrata Avatar
  • jhoffner Avatar
  • g964 Avatar
  • GiacomoSorbi Avatar
  • suic Avatar
  • anter69 Avatar
  • Contessa Avatar
  • kazk Avatar
  • Voile Avatar
  • rowcased Avatar
  • FArekkusu Avatar
  • stellartux Avatar
  • user8436785 Avatar
  • ejini战神 Avatar
  • Just4FunCoder Avatar
  • KayleighWasTaken Avatar
  • metatable Avatar
Ad