7 kyu

Simple Fun #21: Number Of Clans

136 of 266myjinxin2015

Description:

Task

Let's call two integers A and B friends if each integer from the array divisors is either a divisor of both A and B or neither A nor B. If two integers are friends, they are said to be in the same clan. How many clans are the integers from 1 to k, inclusive, broken into?

Example

For divisors = [2, 3] and k = 6, the output should be 4

The numbers 1 and 5 are friends and form a clan, 2 and 4 are friends and form a clan, and 3 and 6 do not have friends and each is a clan by itself. So the numbers 1 through 6 are broken into 4 clans.

Input/Output

  • [input] integer array divisors

    A non-empty array of positive integers.

    Constraints: 2 ≤ divisors.length < 10, 1 ≤ divisors[i] ≤ 10.

  • [input] integer k

    A positive integer.

    Constraints: 5 ≤ k ≤ 50.

  • [output] an integer

Puzzles

Stats:

CreatedJan 24, 2017
PublishedJan 24, 2017
Warriors Trained742
Total Skips57
Total Code Submissions636
Total Times Completed266
JavaScript Completions88
C# Completions50
Python Completions136
Ruby Completions23
Total Stars5
% of votes with a positive feedback rating86% of 92
Total "Very Satisfied" Votes73
Total "Somewhat Satisfied" Votes12
Total "Not Satisfied" Votes6
Total Rank Assessments6
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • hobovsky Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad