Anonymous user
Semiprime: Difference between revisions
no edit summary
m (→{{header|Perl}}: Show how we can use the smoothness test from Pari/GP) |
No edit summary |
||
Line 132:
}</lang>
{{out}}
=={{header|C++}}==
<lang cpp>
#include <iostream>
bool isSemiPrime( int c )
{
int a = 2, b = 0;
while( b < 3 && c != 1 )
{
if( !( c % a ) )
{ c /= a; b++; }
else a++;
}
return b == 2;
}
int main( int argc, char* argv[] )
{
for( int x = 2; x < 100; x++ )
if( isSemiPrime( x ) )
std::cout << x << " ";
return 0;
}
</lang>
{{out}}
<pre>
4 6 9 10 14 15 21 22 25 26 33 34 35 38 39 46 49 51 55 57 58 62 65 69 74 77 82 85 86 87 91 93 94 95
</pre>
=={{header|Common Lisp}}==
<lang lisp>(defun semiprimep (n &optional (a 2))
|