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

Home > Numbers
Just a search (Posted on 2018-08-18) Difficulty: 4 of 5
List all prime numbers below 3000 that can be expressed
as a^2 + n*b^2 for all integer n's from 1 to 10.

No Solution Yet Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
concur Comment 5 of 5 |
For what it's worth, I concur w/ Charlie's solution.

I give my program below, which is about the same length as C's and uses similar methods, but employs an older language (Gnu FORTRAN  vs. VB).

This gives primes that can be formed with all 10 n's:

p = a^3 + n b^2

 We list p, a, n_10, b

1009          10     10

1129     33     10      2

1201     29     10      6

1801     19     10     12

2521     39     10     10

2689     27     10     10

program pp

        implicit none

        integer i,j,k,m,a,b,n,c,list(20000,4),

        1 list1(20000,4),dum1,dum2,dum3,dum4,iold,cnt

        list(1,1)=2

        list(1,2)=1

        list(1,3)=1

        list(1,4)=1

        c=1

        print*,' p = a^2 + n b^2     a      n     b'

           do n=1,10

                do a=1,55

                   do b=1,55

                   i=a**2+n*b**2

                   if((i/2)*2.eq.i)go to 1

                   call isprime(i,m)    

                        if(m.eq.1.and.i.lt.3000)then

c                       print*,i,a,n,b

                        c=c+1

                        list(c,1)=i

                        list(c,2)=a

                        list(c,3)=n

                        list(c,4)=b

                        endif

1                  enddo

                enddo

           enddo

        print*,'c = ',c

           do i=1,c

                do j=i+1,c-1

                   if( list(i,1).gt.list(j,1)  .or.

        1           (  list(i,1).eq.list(j,1) .and.

        2              list(i,3).gt.list(j,3) )   )then

                   dum1=list(i,1)

                   dum2=list(i,2)

                   dum3=list(i,3)

                   dum4=list(i,4)

                   list(i,1)=list(j,1)

                   list(i,2)=list(j,2)

                   list(i,3)=list(j,3)

                   list(i,4)=list(j,4)

                   list(j,1)=dum1

                   list(j,2)=dum2

                   list(j,3)=dum3

                   list(j,4)=dum4

                   endif

                enddo

           enddo


        iold=2

        cnt=0

           do k=1,c

           i=list(k,1)

                if(i.eq.iold)then

                cnt=cnt+1

                   if(cnt.eq.10)then

                   print 2,(list(k,j),j=1,4)

                   cnt=0

                   endif

                else

                iold=i

                cnt=0

                endif

           enddo


c       print 2,(list(1,j),j=1,4)

2       format(4(i4,3x))

        

        end


        subroutine isprime(i,n)

        implicit none

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

        n=0

        k=sqrt(1.*i)

                do j=3,k

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

                l=m*j

                if(l.eq.i)go to 1

                enddo

            n=1  

1       return

        end

Edited on August 19, 2018, 12:38 am
  Posted by Steven Lord on 2018-08-19 00:08:05

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


Search:
Search body:
Forums (1)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (23)
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