You are on page 1of 3

Prime Generator

Problem code: PRIME1 Submit All Submissions Shridhar wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers.

Input
The first line contains t, the number of test cases (less then or equal to 10). Followed by t lines which contain two numbers m and n (1 <= m <= n <= 1000000000, nm<=100000) separated by a space.

Output
For every test case print all prime numbers p such that m <= p <= n, one number per line. Separate the answers for each test case by an empty line.

Example
Input: 2 1 10 35 Output: 2357 35

Warning: large Input/Output data, be careful with certain languages (though most should be OK if the algorithm is well designed) Submit Date: 2008-12-01 Time limit: 6s Source limit: 50000 Languages: C C99 strict C++ PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp HASK CAML CLPS PRLG WSPC BF ICK TEXT
#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; 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; 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;d++) { e=prime(d); if(e==1) cout<<"\n"<<d; } end=clock(); cout<<"\nThe time was: \n"<<((end - start) / CLK_TCK); r=r+(double)((end - start) / CLK_TCK); } cout<<"\nTotal time = "<<r; getch(); }

You might also like