-
Notifications
You must be signed in to change notification settings - Fork 0
/
p10924.cpp
50 lines (47 loc) · 1.06 KB
/
p10924.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
#include <iostream>
#include <cstdio>
using namespace std;
#define N 100000
#define sf scanf
#define pf printf
int isPrime[N];
void SieveOfEratosthenes() {
int i, j;
isPrime[0] = 1;
for(i=4; i<=N; i+=2) {
isPrime[i] = 1;
}
for(i=3; i*i<=N; i+=2) {
if(isPrime[i]==0) {
for(j=i+i; j<=N; j+=i) {
isPrime[j] = 1;
}
}
}
}
int main()
{
SieveOfEratosthenes();
string ch;
int sum , i, x;
while(getline(cin, ch)) {
sum = 0;
for(i=0; ch[i]; i++) {
if(ch[i]>=48 && ch[i]<=57) {
x = ch[i]-48;
sum+=x;
}else if(ch[i]>='a' && ch[i]<='z') {
x = ch[i]-96;
sum+=x;
}else if(ch[i]>='A' && ch[i]<='Z') {
x = ch[i]-38;
sum+=x;
}
}
if(isPrime[sum]==0) {
pf("It is a prime word.\n");
}else {
pf("It is not a prime word.\n");
}
}
}