Multiplicative perfection
Given a positive integer, indicate whether it is the product of its proper divisors.
Integers equal to the product of their proper divisors can be found on the Online Encyclopedia of Integer Sequences as the Multiplicatively perfect numbers.
Input
- A positive integer N.
Output
- An indication of whether N is equal to the product of its proper divisors (that is, the product of all positive integers strictly less than N that divide exactly into N). This can be either:
- One of 2 distinct values.
- Anything that is treated as truthy or falsy by your programming language (not limited to just 2 values).
- Note that the input 1 counts as the product of its proper divisors, despite having no proper divisors. The product of an empty set of numbers is 1.
Examples
Input | Proper divisors | Product | Input = Product ? |
---|---|---|---|
1 | - | 1 | true |
6 | 1, 2, 3 | 6 | true |
8 | 1, 2, 4 | 8 | true |
9 | 1, 3 | 3 | false |
11 | 1 | 1 | false |
12 | 1, 2, 3, 4, 6 | 144 | false |
Test cases
Test cases are in the format input : output
.
Note that the outputs can be any 2 distinct values, or anything truthy or falsy in your programming language. They do not have to be true
and false
.
1 : true
2 : false
3 : false
4 : false
5 : false
6 : true
7 : false
8 : true
9 : false
10 : true
11 : false
12 : false
13 : false
14 : true
15 : true
16 : false
17 : false
18 : false
19 : false
20 : false
21 : true
22 : true
23 : false
24 : false
25 : false
26 : true
27 : true
28 : false
29 : false
30 : false
31 : false
32 : false
33 : true
34 : true
35 : true
36 : false
37 : false
38 : true
39 : true
40 : false
41 : false
42 : false
43 : false
44 : false
45 : false
46 : true
47 : false
48 : false
49 : false
50 : false
51 : true
52 : false
53 : false
54 : false
55 : true
56 : false
57 : true
58 : true
59 : false
60 : false
61 : false
62 : true
63 : false
64 : false
65 : true
66 : false
67 : false
68 : false
69 : true
70 : false
71 : false
72 : false
73 : false
74 : true
75 : false
76 : false
77 : true
78 : false
79 : false
80 : false
81 : false
82 : true
83 : false
84 : false
85 : true
86 : true
87 : true
88 : false
89 : false
90 : false
91 : true
92 : false
93 : true
94 : true
95 : true
96 : false
97 : false
98 : false
99 : false
Scoring
This is a code golf challenge. Your score is the number of bytes in your code. Lowest score for each language wins.
Explanations are optional, but I'm more likely to upvote answers that have one.
[C (gcc)], 53 bytes This us …
2mo ago
Vyxal, 4 bytes ``` KΠ√= …
2mo ago
JavaScript, 36 bytes n= …
2mo ago
Japt v1.4.5, 4 bytes ¶â …
2mo ago
4 answers
C (gcc), 53 bytes
This uses the shortcut behaviour of logical or (||
) to only multiply if it is a divisor; the loop end condition then makes sure it's a proper divisor.
i=1;p=1;f(n){for(;i<n;++i)(n%i)||(p*=i);return p==n;}
0 comment threads
Vyxal, 4 bytes
KΠ√=
Another 4 byter, but uses the definition of A007422 that a number returns true if product(divisors) == input ** 2
.
Explained
KΠ√=
= # Does the
√ # Square root of
KΠ # the product of divisors the input
= # Equal the input?
💎
Created with the help of Luminespire.
1 comment thread