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 925 (Div. 3) 1931D. Divisible Pairs Solution

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

Powered by Blogger.