Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

PRIME1: C++ not getting accepted although giving right answers

$
0
0
#include <iostream>
#include <math.h>
using namespace std;

int main() {
    int t,i;
    long m,n,current,rootn,marker,markeris;
    scanf("%d\n",&t);
    while(t--)
    {
        scanf("%ld %ld",&m,&n);
        rootn=ceil((float)sqrt(n));
        rootn++;
        bool prime[rootn+1];
        bool isprime[n-m+2];
        for(i=0;i<rootn+1;i++) prime[i]=true;
        for(i=0;i<n-m+2;i++) isprime[i]=true;
        current=2;
        while(current<=rootn)
        {
            marker=2;
            while(current*marker<=rootn) 
            {
                prime[current*marker]=false;
                marker++;
            }
            markeris=ceil((float)m/current);
            if(markeris<2) markeris=2;
            while(current*markeris<=n)
            {
                isprime[current*markeris-m]=false;
                markeris++;
            }
            current++;
            while(current<=rootn && !prime[current]) current++;
        }
        for(i=0;i<=n-m;i++) if(isprime[i] && i+m>1) printf("%ld\n",i+m);
        if(t) printf("\n");
    }
    return 0;
}

This is my code. Although it is giving the write answer in ideone but it show wrong answer here. What could be the problem?


Viewing all articles
Browse latest Browse all 40121

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>