Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Multiplicative perfection

+0
−0

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.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Insight found by searching OEIS (2 comments)

4 answers

You are accessing this answer with a direct link, so it's being shown above all other answers regardless of its score. You can return to the normal view.

+1
−0

Japt v1.4.5, 4 bytes

¶â¬×

Try it

¶â¬×     :Implicit input of integer
¶        :Is equal to
 ⬠     :Proper divisors
   ×     :Reduced by multiplication
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

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;}

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

Vyxal, 4 bytes

KΠ√=

Try it Online!

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.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

JavaScript, 36 bytes

n=>n==(g=d=>--d?(n%d?1:d)*g(d):1)(n)

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »