// UVa 10924 - Prime Words
#include <string>
#include <iostream>
#include <string.h>
using namespace std;
#define max 1041
int main() {
// sieve
bool prime[max];
memset(prime, true, sizeof(prime));
for (int i = 4; i < max; i += 2)
prime[i] = false;
for (int i = 3; i < max; i += 2)
if (prime[i]) {
for (int j = i * i; j < max; j += (i << 1))
prime[j] = false;
}
// solve
string word;
while (cin >> word) {
int n = 0;
for (int i = 0; i < word.length(); i++) {
if (word[i] >= 'a')
n += (word[i] - 'a') + 1;
else
n += (word[i] - 'A') + 27;
}
if (prime[n])
cout << "It is a prime word.\n";
else
cout << "It is not a prime word.\n";
}
return 0;
}
Friday, October 16, 2015
UVa 10924 - Prime Words
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment