Spoj Solution PRIONPRI - Prime or not Prime!

Solve in C++:


#include<bits/stdc++.h>
using namespace std;
main()
{

    long long int n,i,a,r,j,f=0;
    scanf("%lld",&n);
    for(i=1;i<=n;i++)
    {
      scanf("%lld",&a);
      r=sqrt(a);
       for(j=2;j<=r;j++)
       {
           if(a%j==0)
           {
              
               f=1;
               break;
           }
       }
       if(f==1)
        printf("NO\n");
       else
       printf("YES\n");
       f=0;
    }
    return 0;
}


2 comments:

  1. This solution is too slow .... Did you even get AC for this on spoj?

    ReplyDelete

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.