0% found this document useful (0 votes)
64 views

Twin Primes

The students are developing a satellite and need twin prime pairs for their encryption technique, where the difference between two prime numbers is 2. The document provides sample input and output to find the count of twin prime pairs between two given numbers to help the students with their encryption design for their communication systems on the satellite. It includes a C++ code to generate the count of twin prime pairs between the given limits by checking if each number is a prime and the next is also prime.

Uploaded by

Nitish Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Twin Primes

The students are developing a satellite and need twin prime pairs for their encryption technique, where the difference between two prime numbers is 2. The document provides sample input and output to find the count of twin prime pairs between two given numbers to help the students with their encryption design for their communication systems on the satellite. It includes a C++ code to generate the count of twin prime pairs between the given limits by checking if each number is a prime and the next is also prime.

Uploaded by

Nitish Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Twin Primes

Problem code: TGPA02 Submit All Submissions The students of IIST are developing their own satellite. The RF & Communications team isdesigning a new encryption technique. They require the usage of of Twin Primes in theircryptographic technique. (A twin prime pair is a pair of prime numbers having a difference of 2.)The more the number of pairs of Twin Primes the better their encryption technique would be andhappier their mentors in ISRO. They don't have any good programmers with them as of now, sothey have asked you to help them generate the count of twin primes between any two givennumbers.

Input Format
The first line will contain the number of test cases, t. For each test case, a single line contains 2 numbers, m and n seperated by a space. t<=20 1<=m<=n<=1000000000 n-m<=1000000

Output Format
The number of pairs of twin primes between m and n.
Sample Input: 2 1 10 100 200 Sample Output: 27

Date: 2010-02-24 Time limit: 1s Source limit:50000 Languages: C C++ 4.3.2

#include<iostream.h> #include<conio.h> #include<math.h> #include<time.h>

#include<stdio.h> int prime(long int a) { long int g,h,j; if(a==1) return 0; for(g=2;g<=sqrt(a);g++) { if(a%g==0) return 0; } return 1; } void main() { clock_t start, end; long int n,m,a,b,c,d,e,f,s=0; double r=0; clrscr(); cout<<"Enter the number of test cases less then 10"<<endl; cin>>a; for(n=1;n<=a;n++) { cout<<"\nEnter limits as 10 34 "<<endl; cin>>b>>c;

start = clock(); for(d=b;d<=(c-2);d++) { e=prime(d); f=prime(d+2); if(e==1 && f==1) s=s+1; } end=clock(); cout<<"\nThe time was: \n"<<((end - start) / CLK_TCK); r=r+(double)((end - start) / CLK_TCK); cout<<"\nTotal twin prime "<<s; s=0; } cout<<"\nTotal time = "<<r; getch(); }

You might also like