BOJ - 2153 - 소수 단어

Updated:

import sys

def solution():
    CHECK = [False, True] + [True] * 2001

    for i in range(2, 2001):
        if CHECK[i]:
            for j in range(2 * i, 2001, i):
                CHECK[j] = False

    alphabet = [
        0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
        'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
        's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
        'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
        'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
    ]

    word = str(input())
    number = 0
    for i in word:
        number += alphabet.index(i)

    if CHECK[number]: print("It is a prime word.")
    else: print("It is not a prime word.")

solution()

https://www.acmicpc.net/problem/2153

Categories:

Updated:

Leave a comment