Home » Ask & Discuss » Board Exams - CBSE, ICSE, State Boards » Computer Science « Back to Discussion



Computer Science

vizay soni's Avatar
Blazing goIITian

Joined: 31 May 2007
Post: 520
6 Apr 2009 18:15:32 IST
0 People liked this
1
962 View Post
Find the first two primes above 1 million, which digit sums are also prime. The solution is the con
None

Find the first two primes above 1 million, which digit sums are also prime.The solution is the concatination of the two numbers,Example: If the first number is 1,234,567and the second is 2,345,678,your solution is 12345672345678


Share this article on:

Comments (1)

Bipin Dubey's Avatar

Forum Expert
Joined: 23 Jan 2007
Posts: 7942
7 Apr 2009 16:05:45 IST
0 people liked this

I am using the fact that prime numbers can only be of the form 6k+1 or 6k+5.

 

Program :

 

n=1000000;

count1=0;

while(count1<2)

{

 count2=0;

 if(n%6==1 || n%6==5)

 {

  for(i=2;i<=sqrt(n);i++)

  {

   if(n%i==0)

   count2=count2+1;

  }

  if(count2==0)

  {

   count1=count1+1;

   printf("%d",n);

  }

  n=n+1;

 }

 else

 n=n+1;

}

 

 




Quick Reply


Reply

Some HTML allowed.
Keep your comments above the belt or risk having them deleted.
Signup for a avatar to have your pictures show up by your comment
If Members see a thread that violates the Posting Rules, bring it to the attention of the Moderator Team
Free Sign Up!

Preparing for IIT-JEE ?

Arihant Revision Package for IIT JEE - Books, Practice Tests + Rank Predictor


@ INR 1,995/-

For Quick Info

Name

Mobile No.

Find Posts by Topics

Physics.

Topics

Mathematics.

Chemistry.

Biology

Parents

Board

Fun Zone

Sponsored Ads