title: prime no. test where i check divisibility of a no. n by every no. that is <= root n (i tried optimising it)
body: <p>question link : <a href="https://www.codechef.com/problems/PRB01" rel="nofollow noreferrer">https://www.codechef.com/problems/PRB01</a></p>
  <p>my code takes t as an input and then takes t no of inputs in the lines that follow, it puts these nos in a function where I check divisibility of a no. n by every no. that is &lt;= root n.
  if n is divisible to i ie (n%i == 0) add 1 to count(which was initially set to 0). I tried optimising with an if statement which would break me out of the loop if count &gt;= 2.
  Finally the function returns 1 if prime and 0 if the no. is composite
  is this approach correct, i get correct answers for the inputs i give but codechef's online judge graded it as wrong</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;math.h&gt;
  
  int prime(int);
  
  int
  main()
  {
      int t;
  
      scanf(&quot;%d&quot;, &amp;t);
      if ((t &gt;= 1) &amp;&amp; (t &lt;= 20)) {
          for (int i = 0; i &lt; t; i++) {
              int n;
  
              scanf(&quot;%d&quot;, &amp;n);
              if (prime(n) == 0)
                  printf(&quot;no\n&quot;);
              else
                  printf(&quot;yes\n&quot;);
          }
      }
      return 0;
  }
  
  int
  prime(int x)
  {
      int count = 0;
      int y = sqrt((double) x);
  
      for (int i = 1; i &lt;= y; i++) {
          if (x % i == 0)
              count++;
          if (count &gt;= 2)
              break;
      }
  
      if (count &lt;= 1)
          return 1;
      else
          return 0;
  }
  </code></pre>