< Back to forum

i am not getting in which test cases my code my code is not working...question: https://www.hackerrank.com/contests/recode-2/challenges/baa-baa-black-sheep/problem

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


#define ll long long
#define pb push_back


int main()
{

ll i,j;

ll prime[31624];

for(i=0;i<31624;i++)
    prime[i]=1;

prime[0]=0;
prime[1]=0;


for(i=2;i<31624;i++)
{
 if(prime[i]==1)
 {
   for(j=2;(i*j)<31624;j++)
   {
    prime[i*j]=0;
   }
 }

}



vector<ll> p;

for(i=0;i<31624;i++)
{
    if(prime[i]==1)
        {
         p.pb(i);
        }
}

for(i=0;i<p.size();i++)
    cout<<p[i]<<" ";



ll t,n,k,m,x,y,p2;

cin>>n>>p2;


ll ans=1;

ll c=0;

if(n==1)
{
 cout<<p2;
}

else
{

if(p2<31623)
{

for(i=0;i<p.size();i++)
{
  if(p[i]==p2)
  {
         if((i+n-2)<p.size())
            {
                ans=p2*p[i+n-2];

                if(ans>1000000000)
                    cout<<"0";

               else
                    cout<<ans;

            }

       break;
 }
}


}


else
 cout<<"0";

}




return 0;
}

 

Asked by: Manish_Kumar_Savita on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.


Enter your answer details below:


Enter your comment details below:




1 Answer(s)

avatar

your code is not printing any output for some of the testcases.
here are some of the testcases on which your code is failing,

INPUT :
1500 13
166666668 3
50000 1381
4000000 19

CORRECT OUTPUT :
93769
0
849076087
420993431

Shubham_Kumar_Gupta last updated on April 7, 2019, 6:34 p.m. 0    Reply    Upvote   

Instruction to write good question
  1. 1. Write a title that summarizes the specific problem
  2. 2. Pretend you're talking to a busy colleague
  3. 3. Spelling, grammar and punctuation are important!

Bad: C# Math Confusion
Good: Why does using float instead of int give me different results when all of my inputs are integers?
Bad: [php] session doubt
Good: How can I redirect users to different pages based on session data in PHP?
Bad: android if else problems
Good: Why does str == "value" evaluate to false when str is set to "value"?

Refer to Stack Overflow guide on asking a good question.