question - https://hack.codingblocks.com/contests/c/537/52
code - https://ide.codingblocks.com/s/41127
My output is correct . But the test case fails due to “Time Limit Exceeded”.i’m unable to further optimise my code. Pls tell me some ways to optimise the above code.
TLE in "Prateek loves candy"
As the complexity of ur code is too high , you need to think in the way of computing sieve .
If you are still stuck , then go through this code
https://ide.codingblocks.com/s/41133
1 Like
#include
#include
using namespace std;
int main(){
int num,i,j,number,c=0,t,n;
cin>>t;
for(i=1;i<=t;i++){
number=0;
num=3;
cin>>n;
for(c=2;c<=n; ){
for(j=2;j<int(sqrt(num));j++){
if(num%j==0)
break;
}
if(num==j){
number=num;
c++;
}
num++;
}
cout<<number<<endl;
}
return 0;
}
1 Like