I implemented using segmented seive.
Problem is with the below mentioned statement in the sieve function:
mark[i*j]=1; // i goes til 10^6 and so does j in your code. Hence, max(i*j)=10^12 thus giving RTE.
I changed the code this way, can you please see to the mistake in this one http://ideone.com/7Hk5mh . Its really going above now… i tried so many test cases, but repeatedly giving WA.
You cannot read the number up to 10^12 in
@betlista it still gives WA!!!