Just another WordPress.com site

খুবই সোজা একটা সমস্যা । শুধু তোমাকে Sieve এর Algorithom ব্যাবহার করা লাগবে । এইবার নিশ্চয় পারবে ।

#include<iostream>
#include<cmath>
#include<string>
using namespace std;

int a[2010];

void seieve(int n)
{
    int imax,i,j,jmax;
   for(i=0;i<=n;i++)
        a[i]=1;
     imax=sqrt(n)+1;
    for(i=2;i<=imax;i++)
    {
        jmax=(n/i)+1;
        if(a[i]==1)
            for(j=2;j<=jmax;j++)
                if(i*j<=n)
                    a[i*j]=0;
    }
}

int main()
{
    int i,sum=0;
    seieve(2005);
    string ab;
    while(cin>>ab)
    {
        for(i=0;i<ab.length();i++)
        {
            if(ab.at(i)>=’a’ && ab.at(i)<=’z’)
                sum+=ab.at(i)-‘a’+1;
            else
                sum+=ab.at(i)-‘A’+27;
        }
        if(a[sum])
            cout<<“It is a prime word.”<<endl;
        else
            cout<<“It is not a prime word.”<<endl;
        sum=0;
    }
    return 0;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: