ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1086. Cryptography

problem 1086
Posted by Ajana 4 Feb 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
Posted by Felix_Mate 4 Feb 2017 15:59
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)