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

Post History

60%
+1 −0
Challenges Multiplicative perfection

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...

posted 2mo ago by celtschk‭

Answer
#1: Initial revision by user avatar celtschk‭ · 2024-10-08T17:24:32Z (about 2 months ago)
# [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.

<!-- language-all: lang-c -->

    i=1;p=1;f(n){for(;i<n;++i)(n%i)||(p*=i);return p==n;}

[Try it online!][TIO-m20pkvq7]

[C (gcc)]: https://gcc.gnu.org/
[TIO-m20pkvq7]: https://tio.run/##LY1BCsIwFET3OcUnUkhsFerSNHoRNzVN9EP7G9Jk1fbsMYqLgZnHgzGnlzE5o26VL3GC5OrmIBR2pOoapaAK5bYJf9QoVbAxBQKvNak9H5DMmAYL3RIHnM/vG2NIEaYeSUi2MoDvpDQ9bQANl1YV5EOBTvBqgCtUy4N481caKP@/Ju/AY0iWF4W7flwsl4rt@QM "C (gcc) – Try It Online"