-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUva-10924.cpp
68 lines (65 loc) · 1.02 KB
/
Uva-10924.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<bits/stdc++.h>
using namespace std;
vector<int>v;
bool ar[10005];
bool isprime(int x)
{
if(x<10005)
{
return ar[x];
}
for(int i=2; i<sqrt(10005); i++)
{
if(x%ar[i]==0)
{
return false;
}
}
return true;
}
void seive(int n)
{
for(int i=4; i<=n; i+=2)
{
ar[i]=1;
}
for(int i=3; i*i<=n; i+=2)
{
if(!ar[i])
{
for(int j=i*i; j<=n; j=j+i)
{
ar[j]=1;
}
}
}
//cout<<n<<endl;
if(isprime(n))
{
cout<<"It is not a prime word."<<endl;
}
else
{
cout<<"It is a prime word."<<endl;
}
}
int main()
{
char c[105];
while(cin>>c)
{
int l=strlen(c),s=0;
for(int i=0; i<l; i++)
{
if(c[i]>='a' && c[i]<='z')
{
s+=c[i]-'a'+1;
}
else
{
s+=c[i]-'A'+27;
}
}
seive(s);
}
}