Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Is it almost-prime?

Sandbox

Definition: A positive integer n is almost-prime, if it can be written in the form n=p^k where p is a prime and k is also a positive integers. In other words, the prime factorization of n contains only the same number.

Input: A positive integer 2<=n<=2^31-1

Output: a truthy value, if n is almost-prime, and a falsy value, if not.

Truthy Test Cases:

2
3
4
8
9
16
25
27
32
49
64
81
1331
2401
4913
6859
279841
531441
1173481
7890481
40353607
7528289

Falsy Test Cases

6
12
36
54
1938
5814
175560
9999999
17294403

Please do not use standard loopholes. This is so the shortest answer in bytes wins!

Answer*

Draft saved
Draft discarded
Cancel
3
  • \$\begingroup\$ @petStorm Here it is :) Thanks! \$\endgroup\$ Commented Aug 26, 2020 at 11:13
  • \$\begingroup\$ Save 13 bytes by ditching the named function. Try it online! \$\endgroup\$ Commented Mar 31, 2021 at 9:53
  • \$\begingroup\$ @chunes Thanks! I didn't know it's allowed when I posted it. I have at least dozen more submission using this form. \$\endgroup\$ Commented Mar 31, 2021 at 10:09

AltStyle によって変換されたページ (->オリジナル) /