Uva 10042 Smith Numbers

Nov 17, 2009

Problem: 10042.Smith Numbers
Tips:
1. First initialize prime number , in special way
          
How we generate prime number:
Let: p[]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; ie p[ele]=1 means ele is a prime.
Take i=2 which is prime, Now p[2]=0,p[4]=0,p[6]=0,p[8]=0,p[10]=0;p[12]=0;p[14]=0;
So now p[]={1,1,1,1,0,0,1,0,1,0,1,0,1,0,1}
Take i=3 which is prime, Now p[6]=0,p[9]=0;p[12]=0;p[15]=0;
So now p[]={1,1,1,1,0,1,0,1,0,0,0,1,0,1,0,0}
For i=4 , i<=sqrt(16) false so end
P[0]=1 ;p[1]=1,p[2]=1;p[3]=1;p[5]=1,p[7]=1;p[11]=1;p[13]=1;
Move a[0]=0,a[1]=1;a[2]=2;a[3]=3;a[4]=5;a[5]=7;a[6]=11;a[7]=13
2. Then sum each digit
3. Find per factor, find sum of digit of that factor, then add it with total sum
4. Check it not prime and totals are equal.

Code In C/C++:

No comments:

Post a Comment