**my below solution of PRIME1 problem is giving time limit exceed to my code…**

*can anyone explain time Complexity Analysis of my solution, and what changes should i perform to decrese time limit*

**any suggestion for solution update required**

```
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package PracticeMedium;
import java.util.Scanner;
/**
*
* @author Hemant Dhanuka
*/
class Prime1_1 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int noOfCases = s.nextInt();
for (int i = 0; i < noOfCases; i++) {
int m = s.nextInt();
int n = s.nextInt();
calculatePrime(m, n);
System.out.println();
}
}
private static void calculatePrime(int m, int n) {
int count = 0;
if (m == 1) {
m = m + 1;
}
for (int i = m; i <= n; i++) {
boolean isPrime = true;
for (int j = 2; j <= Math.sqrt(i); j++) {
if (i % j == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
count++;
}
}
System.out.println(count);
}
}
```

**due to suggestion, i tried to solve PRIME1 with “sieve of Eratoshenes”… but got TLE again**

```
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//package PracticeMedium;
import java.util.Scanner;
/**
*
* @author Hemant Dhanuka
*/
class Prime1_SieveOfEratosthenes1 {
static int b = 1000000001; //1000000001;
static boolean a[] = new boolean[b];
public static void main(String[] args) {
a[0] = true;
a[1] = true;
Scanner s = new Scanner(System.in);
int noOfCases = s.nextInt();
calculate();
for (int i = 0; i < noOfCases; i++) {
int firstNo = s.nextInt();
int lastNo = s.nextInt();
printPrimeNo(firstNo, lastNo);
System.out.println();
}
}
private static void calculate() {
for (int i = 2; i < Math.sqrt(b); i++) {
if (!a[i]) { //a[i]==false
int p = 2;
for (int j = i; i * p <b ; p++) {
j = i * p;
a[j] = true;
}
}
}
System.out.println("hello");
}
private static void printPrimeNo(int firstNO, int lastNo) {
for (int i = firstNO; i <= lastNo; i++) {
if (!a[i]) {
System.out.println(i);
}
}
}
}
```

*plase explain time analysis of "Sieve of Eratosthenes
" solution… and why its giving TLE error…*