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

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.