How to find a sphenic number

bool isSphenic (int numbers){

int i,j,arr[numbers+1],ans ;
arr[0]=0 ;
arr[1]=1 ;
ans=0 ;

for(i=0;i<=numbers;i++)
arr[i]=1 ;

for(i=2;i<=numbers;i++)
{
for(j=i+1;j<=numbers;j++)
if(j%i==0)
arr[j]=0 ;
}



Last edited on
Please edit your post to put [code][/code] tags (the <> icon) around your code.

Then add some text to your post with an actual question as to what is wrong with your code.
- it doesn't compile
- it doesn't run
- it produces some correct answers
- it crashes if ....

Perhaps a link to what sphenic numbers are (because I'm too lazy to google).
Factorise your number by scanning from 2, 3, ..., sqrt(N). Divide out each factor as you find it (which must therefore be prime); if any factor is repeated then the number isn't sphenic. Anything left is prime.

A sphenic number is one which has precisely three, distinct prime factors. The smallest is 2x3x5=30.

Yes!! 42 is sphenic!

Last edited on
Topic archived. No new replies allowed.