結果

問題 No.889 素数!
ユーザー yomo3
提出日時 2020-02-12 01:59:27
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,324 bytes
コンパイル時間 409 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-10-01 15:19:05
合計ジャッジ時間 3,291 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

def isprime(p):
    if p <= 1:
        return False
    if p == 2:
        return True
    if p % 2 == 0:
        return False;
    lim = int(p**0.5)+1
    for q in range(3, lim, 2):
        if p % q == 0:
            return False
    return True

def issquare(n):
    f = (0,0,1,1,0,1,1,1,1,0,1,1,1,1,1,1)
    if f[n & 0xf]:
         return False
    l, r = 1, n
    while l <= r:
        m  = l + (r - l) // 2
        m2 = m * m
        if m2 < n:
            l = m + 1
        elif m2 > n:
            r = m - 1
        else:
            return True
    return False        

def iscubic(n):
    l, r = 1, n
    while l <= r:
        m  = l + (r - l) // 2
        m3 = m * m * m
        if m3 < n:
            l = m + 1
        elif m3 > n:
            r = m - 1
        else:
            return True
    return False        

# https://oeis.org/A000396
def isperfect(n):
    return  n in (
        6, 28, 496, 8128, 33550336, 8589869056,
        137438691328, 2305843008139952128,
        #2658455991569831744654692615953842176,
        #191561942608236107294793378084303638130997321548169216
    )

N = int(input())

if isprime(N):
    ans = 'Sosu!'
elif N >= 2 and issquare(N):
    ans = 'Heihosu!'
elif N >= 2 and iscubic(N):
    ans = 'Ripposu!'
elif isperfect(N):
    ans = 'Kanzensu!'
else:
    ans = N

print(ans)
0