Runtime error time: 0.06 memory: 4386816 signal:-1

96
July 16, 2017, at 9:03 PM

I got Runtime error time: 0.06 memory: 4386816 signal:-1 for the following code on ideone.com . The code is for displaying prime numbers . The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.

import java.util.*;
import java.lang.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    for (int i=0;i<n;i++)
    {
        int n1=sc.nextInt();
        int n2=sc.nextInt();
        for(int j=n1;j<=n2;j++)
        {
            if( j==2 || j==3)
            {
                System.out.println(j);
            }
            if( j%2 != 0 && j%3 != 0 && j!=1)
            {
                System.out.println(j);
            }
        }
    }
}
}
Answer 1

The problem is, that you try to scan numbers more than one time, because nextInt() is in for cycle. Try to put

int n1=sc.nextInt(); int n2=sc.nextInt();

before for (int i=0;i<n;i++).

READ ALSO
Message broker data storage format?

Message broker data storage format?

When java producer sends the data any message broker(MB) queue/topic like Apache Kafka/active MQ, it serializes the data and sends the dataDoes MB deserializes the data and then storing it or just stores the object as it is(in serialized form)?

96
Influxdb Versioning / Audit Data

Influxdb Versioning / Audit Data

Suppose simple measurement 'price':

95
How to make an optional/nullable property in Hibernate/JPA

How to make an optional/nullable property in Hibernate/JPA

I found this implementation that basically do what I want

92