1 / 2
Nov 2012

include

using namespace std;
main()
{
int i,t,j,count;
cin >> t;
int m[t];
int n[t];
for(i=0;i {
cin >> m[i] >> n[i];
}
for(i=0;i {
if(m[i]>=1 && m[i]<=n[i]&& n[i] <= 1000000000 && n[i]-m[i] <= 100000)
{
while(m[i]<=n[i])
{
count=0;
for(j=1;j<=m[i];j++)
if((m[i]%j)==0)
count++;
if(count==2)
{
cout << m[i] << '\n';
}
m[i]++;
}
}
cout << '\n';
}
return 0;
}

o/p:
2
1 10
1 100
2
3
5
7

2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97

Process returned 0 (0x0) execution time : 9.032 s
Press any key to continue.

stil timelimit is exceeding................
pls hlp me blush

  • created

    Nov '12
  • last reply

    Dec '12
  • 1

    reply

  • 187

    views

  • 2

    users

hello ...
if you know algorithmes analyzsis you can see here the BIG mistake you do ,,,
[quote]

for(j=1;j<=m[i];j++)
if((m[i]%j)==0)
count++;

[/quote]
for every m[i] you should do m[i]*m[i] process !!!
if you want to know if 100,000 is prime or no ,,, you do 10,000,000,000 process
and this isn't every thing ... you do that for all numbers between m and n .... OH MY GOD... if m=1 and n=1000
you do 1*1+2*2+3*3+4*4+.....999*999 process
you should read more about test primelity....
thank you smile
good by

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 14 7d

Want to read more? Browse other topics in C and C++ or view latest topics.