12
\$\begingroup\$

How to spot them

Take a positive integer k. Find its divisors. Find the distinct prime factors of each divisor. Sum all these factors together. If this number (sum) is a divisor of k (if the sum divides k) then, this number k, is a BIU number

Examples

Let's take the number 54
Find all the divisors: [1, 2, 3, 6, 9, 18, 27, 54]
Find the distinct prime factors of each divisor
NOTE: For the case of 1 we take as distinct prime factor 1

1  -> 1  
2  -> 2  
3  -> 3  
6  -> 2,3  
9  -> 3  
18 -> 2,3  
27 -> 3  
54 -> 2,3 

Now we take the sum of all these prime factors
1+2+3+2+3+3+2+3+3+2+3=27
27 divides 54 (leaves no remainder)
So, 54 is a BIU number.

Another (quick) example for k=55
Divisors: [1,5,11,55]
Sum of distinct prime factors: 1+5+11+5+11=33
33 is NOT a divisor of 55, that's why 55 is NOT a BIU number.

BIU numbers

Here are the first 20 of them:

1,21,54,290,735,1428,1485,1652,2262,2376,2580,2838,2862,3003,3875,4221,4745, 5525,6750,7050...

but this list goes on and there are many BIU numbers that are waiting to be descovered by you!

The Challenge

Given an integer n>0 as input, output the nth BIU number

Test Cases

Input->Output

1->1  
2->21   
42->23595  
100->118300    
200->415777    
300->800175    

This is .Shortest answer in bytes wins!

\$\endgroup\$
5
  • 2
    \$\begingroup\$ But 1 is not prime... \$\endgroup\$
    – Stephen
    Sep 27, 2017 at 0:38
  • 3
    \$\begingroup\$ @Stephen thats why I said "For the case of 1 we take as distinct prime factor 1". This is my challenge and this is one of the rules of this challenge.I didn't say that 1 is prime. \$\endgroup\$
    – user72253
    Sep 27, 2017 at 0:42
  • 4
    \$\begingroup\$ Why are the numbers called "BIU"? \$\endgroup\$ Sep 27, 2017 at 1:08
  • 4
    \$\begingroup\$ I'm not sure but I think that it has to do with bisexual intellectual unicorns using them in their everyday life (not in our universe of course...) \$\endgroup\$
    – user72253
    Sep 27, 2017 at 1:13
  • 5
    \$\begingroup\$ Downvoters, don't be shy. Share your thoughts with the rest of us. \$\endgroup\$
    – user72253
    Sep 27, 2017 at 13:17

8 Answers 8

6
\$\begingroup\$

Jelly, 16 15 bytes

ÆDÆfQ€SS‘ḍ
1Ç#Ṫ

Try it online!

Woohoo for builtins (but they mysteriously hide from me sometimes so -1 byte thanks to @HyperNeutrino)

How it Works

ÆDÆfQ€SS‘ḍ - define helper function: is input a BIU number?
ÆD             - divisors
  Æf           - list of prime factors
    Q€         - now distinct prime factors
      SS       - sum, then sum again ('' counts as 0)
        ‘      - add one (to account for '')
         ḍ     - does this divide the input?

1Ç#Ṫ - main link, input n
  #     - starting at 
1          - 1
        - get the first n integers which meet:
 Ç         - helper link
   Ṫ    - tail
\$\endgroup\$
3
  • \$\begingroup\$ -1 byte using ÆfQ€ instead of ÆFḢ€€ \$\endgroup\$
    – hyper-neutrino
    Sep 27, 2017 at 0:56
  • 2
    \$\begingroup\$ but they mysteriously hide from me sometime "Jelly is a game of atom hide and programmer seek" ~ i cri everytim \$\endgroup\$
    – hyper-neutrino
    Sep 27, 2017 at 1:14
  • \$\begingroup\$ I think you can save 1 byte with ÆDÆFSSḢ‘ḍ. \$\endgroup\$
    – Arnauld
    Sep 27, 2017 at 16:11
5
\$\begingroup\$

05AB1E, 9 bytes

µNNÑfOO>Ö

Uses teh 05AB1E encoding. Try it online!

\$\endgroup\$
4
\$\begingroup\$

Husk, 13 bytes

!fṠ¦ö→ΣṁoupḊN

Try it online!

Explantaion

  Ṡ¦ö→ΣṁoupḊ    Predicate: returns 1 if BIU, else 0.
           Ḋ    List of divisors
       ṁ        Map and then concatenate
        oup     unique prime factors
      Σ         Sum
    ö→          Add one
  Ṡ¦            Is the argument divisible by this result
 f          N   Filter the natural numbers by that predicate
!               Index
\$\endgroup\$
3
\$\begingroup\$

Mathematica, 85 bytes

If[#<2,1,n=#0[#-1];While[Count[(d=Divisors)@++n,1+Tr@Cases[d/@d@n,_?PrimeQ,2]]<1];n]&
\$\endgroup\$
2
\$\begingroup\$

Actually, 16 bytes

u⌠;÷♂y♂iΣu@%Y⌡╓N

Try it online!

Explanation:

u⌠;÷♂y♂iΣu@%Y⌡╓N
u⌠;÷♂y♂iΣu@%Y⌡╓   first n+1 numbers x starting with x=0 where
   ÷                divisors
    ♂y              prime factors of divisors
      ♂iΣu          sum of prime factors of divisors, plus 1
  ;       @%        x mod sum
            Y       is 0
               N  last number in list
\$\endgroup\$
2
\$\begingroup\$

Pyth, 22 bytes

e.f|qZ1!%Zhssm{Pd*M{yP

Try it here!

This is my first ever Pyth solution, I began learning it thanks to the recommendations of some very kind users in chat :-)... Took me about an hour to solve.

Explanation

e.f|qZ1!%Zhssm{Pd*M{yP  - Whole program. Q = input.

 .f                     - First Q integers with truthy results, using a variable Z.
     qZ1                - Is Z equal to 1?
   |                    - Logical OR.
                   {yP  - Prime factors, powerset, deduplicate.
                 *M     - Get the product of each. This chunck and ^ are for divisors.
              m}Pd      - Get the unique prime factors of each.
           ss           - Flatten and sum.
          h             - Increment (to handle that 1, bah)
       %Z               - Modulo the current integer by the sum above.
      !                 - Logical negation. 0 -> True, > 0 -> False.
e                       - Last element.
\$\endgroup\$
1
\$\begingroup\$

Haskell, 115 bytes

All of the list comprehensions here can probably be golfed down, but I'm not sure how. Golfing suggestions welcome! Try it online!

x!y=rem x y<1
b n=[a|a<-[1..],a!(1+sum[sum[z|z<-[2..m],m!z,and[not$z!x|x<-[2..z-1]]]|m<-[x|x<-[2..a],a!x]])]!!(n-1)

Ungolfing

This answer is actually three functions mashed together.

divisors a = [x | x <- [2..a], rem a x == 0]
sumPrimeDivs m = sum [z | z <- [2..m], rem m z == 0, and [rem z x /= 0 | x <- [2..z-1]]]
biu n = [a | a <- [1..], rem a (1 + sum [sumPrimeDivs m | m <- divisors a]) == 0] !! (n-1)
\$\endgroup\$
0
\$\begingroup\$

Japt, 22 21 17 bytes

I feel like the g function method should lead to a shorter solution, but I can't figure out how it works! Nope! Wrong method! But, in my defense, the i method didn't exist at the time.

1-indexed.

ÈvXâ mk câ x Ä}iU

Try it

ÈvXâ mk câ x Ä}iU     :Implicit input of integer U
È                     :Function taking an integer X as argument
 v                    :  Test X for divisibility by
  Xâ                  :    Divisors of X
     m                :    Map
      k               :      Prime factors
        c             :    Flatten after
         â            :      Deduplicating
           x          :    Reduce by addition
             Ä        :    Add 1
              }       :End function
               iU     :Get the Uth integer that returns true
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.