CodeForces 230B

Solve  in C:


#include<stdio.h>
#include<math.h>
int sz=1000000;
int vis[1000005]= {0};
void sieve()
{
    int k=sqrt(sz),i,j;
    for(i=2; i<=k; i++)
    {
        if(vis[i]==0)
        {
            for(j=2*i; j<=sz; j+=i)
            {
                vis[j]=1;
            }
        }
    }
    vis[1]=1;
}

int main()
{
     long long int n,f,a,k;
    sieve();
    scanf("%lld",&a);
    for(k=1;k<=a;k++)
    {
    scanf("%lld",&n);

    {
        f=sqrt(n);
        if((f*f)==n)
        {

            if(vis[f]==0)
            {
                printf("YES\n");
            }
            else
            {
                printf("NO\n");
            }
        }
        else
        {
            printf("NO\n");
        }

    }
    }
    return 0;
}


No comments

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.