UVa 10924 Prime Words: Primes

Source: Internet
Author: User

10924-prime Words

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1865

A prime number is a number this has only two divisors:itself and the number one. Examples of prime numbers are:1, 2, 3, 5,, and 10007.

In this problem your should read a set of words, each word is composed only by letters in the rangea-z and A-Z. Each letter has a specific value, the Lettera are worth 1, letter B are worth2 and so on until letter Z-is worth 26. In the same way, letter A is worth, letterb are worth and letter Z are worth52.

You are should write a program to determine if a word was a prime word or not. A word is a prime word if the sum of the IT letters is a prime number.
Input

The input consists of a set of words. Each word was in a line by itself and HasL letters, where 1≤l≤20. The input is terminated by Enf of file (EOF).
Output

For each word you should print:it are a prime word., if the sum of the letters of the word is a prime number, otherwise yo U should print:it is not a prime word ...
Sample Input

Ufrn
Contest
Acm

Sample Output

It is a prime word.
It is not a prime word.
It is not a prime word.

Water problem.

Complete code:

/*0.009s*/
    
#include <cstdio>  
    
char s[25];  
    
int main ()  
{  
    int i, sum;  
    char* p;  
    BOOL Notprime;  
    while (gets (s))  
    {  
        sum = 0;  
        for (p = s; *p; ++p)  
            sum + = (*p >= ' a '? *p &: (*p &) +);  
        Notprime = false;  
        for (i = 2; I * i <= sum; ++i)///because the largest also 52*20=1040, the open root of the whole is 32, so directly calculate  
            if (sum% i = = 0)  
            {  
                notprime = true;< C18/>break;  
            }  
        Puts (notprime?) ' It is not a prime word. ': ' It is a prime word. '  
    return 0;  
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.