#include<bits/stdc++.h>
using namespace std;
#define N 1500
int p[N+1];
void prime()
{
int i, j, l;
l = sqrt(N);
p[0] = 1;
for(i=4;i<=N;i+=2)
p[i] = 1;
for(i=3;i<=N;i+=2)
{
if(p[i] == 0)
{
if(i <= l)
{
for(j=i*i;j<=N;j+=i)
{
p[j] = 1;
}
}
}
}
}
int main()
{
prime();
string s;
while(cin >> s)
{
int l = s.size(), i, sum = 0;
for(i=0; i<l; i++)
{
if(s[i] >= 'a' && s[i] <= 'z')
{
sum += (s[i] - 96);
}
else if(s[i] >= 'A' && s[i] <= 'Z')
{
sum += (s[i] - 38);
}
}
if(p[sum] == 0)
{
cout << "It is a prime word." << endl;
}
else
{
cout << "It is not a prime word." << endl;
}
}
return 0;
}
using namespace std;
#define N 1500
int p[N+1];
void prime()
{
int i, j, l;
l = sqrt(N);
p[0] = 1;
for(i=4;i<=N;i+=2)
p[i] = 1;
for(i=3;i<=N;i+=2)
{
if(p[i] == 0)
{
if(i <= l)
{
for(j=i*i;j<=N;j+=i)
{
p[j] = 1;
}
}
}
}
}
int main()
{
prime();
string s;
while(cin >> s)
{
int l = s.size(), i, sum = 0;
for(i=0; i<l; i++)
{
if(s[i] >= 'a' && s[i] <= 'z')
{
sum += (s[i] - 96);
}
else if(s[i] >= 'A' && s[i] <= 'Z')
{
sum += (s[i] - 38);
}
}
if(p[sum] == 0)
{
cout << "It is a prime word." << endl;
}
else
{
cout << "It is not a prime word." << endl;
}
}
return 0;
}
Comments
Post a Comment