-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2153.cpp
57 lines (51 loc) · 958 Bytes
/
2153.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
// 2153. 소수 단어
// 2020.07.03
// 수학
#include<iostream>
#include<string>
using namespace std;
int PrimeArray[1051];
void PrimeCheck()
{
for (int i = 2; i <= 1050; i++)
{
PrimeArray[i] = 1;
}
for (int i = 2; i * i <= 1050; i++)
{
if (PrimeArray[i])
{
for (int j = i * i; j <= 1050; j += i)
{
PrimeArray[j] = false;
}
}
}
}
int main()
{
string s;
cin >> s;
int num = 0;
for (int i = 0; i < s.size(); i++)
{
if (s[i] >= 'a' && s[i] <= 'z')
{
num += s[i] - 'a' + 1;
}
else if (s[i] >= 'A' && s[i] <= 'Z')
{
num += s[i] - 'A' + 27;
}
}
PrimeCheck();
if (PrimeArray[num] == 1 || num == 1)
{
cout << "It is a prime word." << endl;
}
else
{
cout << "It is not a prime word." << endl;
}
return 0;
}