|
|
вернуться в форумproblem 1086 Послано Ajana 4 фев 2017 11:04 #include<stdio.h> int main() { int n,i,j,c,t,T; scanf("%d",&T); while(T--) { scanf("%d",&n); for(j=2;;j++) { c=0; t=0; for(i=2;i<=j/2;i++) { if(j%i==0) { c++; break; } } if(c==0) t++; if(t==n) { printf("%d\n",j); break; } } } return 0; } why TLE?? Edited by author 04.02.2017 11:04 Edited by author 04.02.2017 11:05 Edited by author 04.02.2017 11:08 Re: problem 1086 Error here: t=0. You wanted this: #include<stdio.h> int main() { int n,i,j,c,t,T; scanf("%d",&T); while(T--) { scanf("%d",&n); t=0; for(j=2;;j++) { c=0; for(i=2;i<=j/2;i++) { if(j%i==0) { c++; break; } } if(c==0) t++; if(t==n) { printf("%d\n",j); break; } } } return 0; } But your algo will get TL on test: 15000 15000 .... 15000 (15001 times) |
|
|