26
3
Surprisingly, I don't think we have a code-golf question for determining if a number is semiprime.
A semiprime is a natural number that is the product of two (not necessarily distinct) prime numbers.
Simple enough, but a remarkably important concept.
Given a positive integer, determine if it is a semiprime. Your output can be in any form so long as it gives the same output for any truthy or falsey value. You may also assume your input is reasonably small enough that performance or overflow aren't an issue.
Test cases:
input -> output
1 -> false
2 -> false
3 -> false
4 -> true
6 -> true
8 -> false
30 -> false (5 * 3 * 2), note it must be EXACTLY 2 (non-distinct) primes
49 -> true (7 * 7) still technically 2 primes
95 -> true
25195908475657893494027183240048398571429282126204032027777137836043662020707595556264018525880784406918290641249515082189298559149176184502808489120072844992687392807287776735971418347270261896375014971824691165077613379859095700097330459748808428401797429100642458691817195118746121515172654632282216869987549182422433637259085141865462043576798423387184774447920739934236584823824281198163815010674810451660377306056201619676256133844143603833904414952634432190114657544454178424020924616515723350778707749817125772467962926386356373289912154831438167899885040445364023527381951378636564391212010397122822120720357
-> true, and go call someone, you just cracked RSA-2048
This is code-golf, so standard rules apply!
4@WheatWizard There's a slightly difference in that that one asks for 3 primes (not a big difference for almost all languages) and it's for distinct primes only (fairly different for some languages). I can discuss it with you in chat if you'd like to continue a more detailed discussion. – HyperNeutrino – 2017-08-07T18:30:02.283
@HyperNeutrino I think the difference is negligible. How many product of n primes questions are we going to allow? In my opinion we already have enough and this new one adds nothing interesting to the mix. – Post Rock Garf Hunter – 2017-08-07T18:32:08.440
2@WheatWizard You raise a good point, but similarly, we already have a bunch of many types of questions, and although, in contrast to what you express, most of them do add significant contribution to their area, this question has enough of a difference that I would believe that it warrants a separate question/post. – HyperNeutrino – 2017-08-07T18:33:39.873
2@hyperneutrino looking at the answers on both challenges, it looks like the difference is a single number in the source code, 2 vs 3. I would hardly call that a big difference. – Post Rock Garf Hunter – 2017-08-07T18:37:52.727
2@WheatWizard There is also "distinct" vs "not distinct"... – HyperNeutrino – 2017-08-07T18:40:42.563
2@WheatWizard For example, if you compare the Jelly answer on that one:
ÆEḟ0⁼7B¤
to the Jelly answer on this one:ÆfL=2
, you'll notice that there is a significant difference; namely, that one has to check for distinctness. – HyperNeutrino – 2017-08-07T18:41:56.550You're my hero, @HyperNeutrino. In the future I'll look for further distinct questions. – Lord Farquaad – 2017-08-07T18:49:24.630
@HyperNeutrino We disagree, I don't think this is worth arguing any further. – Post Rock Garf Hunter – 2017-08-07T18:49:43.437
3@LordFarquaad Just because its a duplicate doesn't mean it is bad. In my mind being a duplicate is a good thing, it means that you are asking a thing that the community finds interesting enough to have already asked about. – Post Rock Garf Hunter – 2017-08-07T18:50:44.510
@WheatWizard Agreed. (well, disagreed). I'd rather not argue further. It's borderline dupe but it's been antihammered so I won't bother arguing for either side for this question's sake :P – HyperNeutrino – 2017-08-07T18:50:51.760
OEIS A001358 – Stephen – 2017-08-07T19:04:47.437
Subset of this and (partially) this
– Okx – 2017-08-07T19:11:21.960If you can work out that some very large number is a semiprime that doesn't mean you've cracked RSA-2048, does it? Don't you need to know the two prime factors as well as that it's semiprime to crack it? – CJ Dennis – 2017-08-08T12:04:00.000
@CJDennis You're right, but is there a test for semi-primeness beyond calculating the factors and counting them? From what I've seen (which admittedly is not a lot), finding the factors is necessary to test semi-primeness, you just don't hold onto them. – Lord Farquaad – 2017-08-08T12:32:27.937