Monday, March 21, 2016

efficient code for prime number

#include<bits/stdc++.h>
using namespace std;

bool prime(long long a)
{
    long long b=0,i;
    for(i=2; i*i<=a; i++)
        if(a%i==0)
            return 0;
    return 1;
}


int main()
{
    long long t,m,n;
    cin>>t;
    for(long long i=0; i<t; i++)
    {
        cin>>n>>m;
        for(long long j=n; j<=m; j++)
        {
            if(prime(j)==1&&j!=1)
                cout<<j<<endl;
        }
        cout <<endl;
    }
    return 0;
}

No comments:

Post a Comment

Speedup Android Studio

Go to Help ->Edit Custom VM Options, and chnge this 4 setting. After that close your Android Studio. This settings are for 8gb of ram pc...