All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers > Sequences
Emirps census (Posted on 2018-10-12) Difficulty: 2 of 5
An emirp (prime spelled backwards) is a prime number that results in a different prime when its decimal digits are reversed.
This definition excludes the related palindromic primes.

13, 17, 31, 37, 71... are emirps.


List values of q(n) (the number of emirps of length n) for n=2 to 6.

No Solution Yet Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
different language, same answer Comment 2 of 2 |

digits            2           3           4           5           6

 emips          4          14         102         703        4769

 pals             1          15           0          93           0

The code here is far cruder than Charlie's. But, this does make it a bit easier to follow. :-)


program pp

        implicit none

        integer i,j,flag1,flag2,e2,e3,e4,e5,e6,

        1 p1,p2,p3,p4,p5,p6

        data e2,e3,e4,e5,e6,p2,p3,p4,p5,p6/10*0/

           do i=3,999999,2

           call isprime(i,flag1)

                if(flag1.eq.1)then

                call rev(i,j)

                call isprime(j,flag2)

                   if(flag2.eq.1.and.i.ne.j)then

                   if(i.ge.10.and.i.le.99)e2=e2+1

                   if(i.ge.100.and.i.le.999)e3=e3+1

                   if(i.ge.1000.and.i.le.9999)e4=e4+1

                   if(i.ge.10000.and.i.le.99999)e5=e5+1

                   if(i.ge.100000.and.i.le.999999)e6=e6+1

                   endif


                   if(flag2.eq.1.and.i.eq.j)then

                   if(i.ge.10.and.i.le.99)p2=p2+1

                   if(i.ge.100.and.i.le.999)p3=p3+1

                   if(i.ge.1000.and.i.le.9999)p4=p4+1

                   if(i.ge.10000.and.i.le.99999)p5=p5+1

                   if(i.ge.100000.and.i.le.999999)p6=p6+1

                   endif            

                endif

           enddo

        print*,'emips ',e2/2,e3/2,e4/2,e5/2,e6/2

        print*,'pals  ',p2,p3,p4,p5,p6

        end


        subroutine rev(i,j)

        implicit none

        integer i,j,k,i1,i2,i3,i4,i5,i6

        k=i

        i1=k/10**5

        k=k-i1*10**5

        i2=k/10**4

        k=k-i2*10**4

        i3=k/10**3

        k=k-i3*10**3

        i4=k/10**2

        k=k-i4*10**2

        i5=k/10

        i6=k-i5*10

        j=((((i6*10+i5)*10+i4)*10+i3)*10+i2)*10+i1

        do 1 k=1,5

1          if((j/10)*10.eq.j)j=j/10

        return

        end

        subroutine isprime(i,n)

        implicit none

        integer i,j,k,l,m,n

        n=0

        k=sqrt(1.*i)

                do j=2,k

                m=(1.*i)/(1.*j)

                l=m*j

                if(l.eq.i)go to 1

                enddo

            n=1  

1       return

        end


Edited on October 12, 2018, 10:02 pm
  Posted by Steven Lord on 2018-10-12 21:44:48

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (0)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information