Problem p02722 (python)

Fixed submission:

def make_divisors(n):
    divisors = []
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    divisors.append(n)
    return divisors

def check(N,K):
    try:
        if N == K:
            return True
        if N % K ==1:
            return True
        if N<K:
            return False
        
        if N % K ==0:
            return check(N//K,K)
        else:
            return False
    except:
        return False

def resolve():
    N = int(input())
    ys= set(make_divisors(N))
    ys2= set([i for i in make_divisors(N-1) if check(N,i)])

    x =set([i for i in ys if check(N,i)])

    print(len(x | ys2))


if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):

def make_divisors(n):
    divisors = []
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    divisors.append(n)
    return divisors

def check(N,K):
    if N == K:
        return True
    if N % K ==1:
        return True
    if N<K:
        return False
    
    if N % K ==0:
        return check(N//K,K)
    else:
        return False


def resolve():
    N = int(input())
    ys= set(make_divisors(N))
    ys2= set([i   for i in make_divisors(N-1) if check(N,i)])
    x =set([i for i in ys|ys2 if check(N,i)])

    print(len(x | ys2))


if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):

def make_divisors(n):
    divisors = []
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    divisors.append(n)
    return divisors

def check(N,K):
    if N == K:
        return True
    if N % K ==1:
        return True
    if N<K:
        return False
    
    if N % K ==0:
        return check(N//K,K)
    else:
        return False


def resolve():
    N = int(input())
    ys= set(make_divisors(N))
    ys2= set(make_divisors(N-1))
    x =set([i for i in ys2 if check(N,i)])
    x2 =set([i for i in ys if check(N,i)])

    print(len(x|x2))


if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):

def make_divisors(n):
    divisors = []
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    divisors.append(n)
    return divisors

def check(N,K):
    if N == K:
        return True
    if N % K ==1:
        return True
    if N<K:
        return False
    
    if N % K ==0:
        return check(N//K,K)
    else:
        return False


def resolve():
    N = int(input())
    ys= set(make_divisors(N))
    ys2= set(make_divisors(N-1))
    x =set([i for i in ys|ys2 if check(N,i)])

    print(len(x))


if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):

import sys

sys.setrecursionlimit(10000)


#約数リスト
def make_divisors(n):
    divisors = []
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    divisors.append(n)
    return divisors

def sosou(N):
    a=[]
    for i in range(2,int(N**0.5+1)):
        if N % i ==0:
            print(a[1])
    print(True)



def check(N,K):
    if N<K:
        return N==1
    
    if N % K ==0:
        return check(N//K,K)
    else:
        return N % K == 1





def resolve():
    N = int(input())
    ys= make_divisors(N)
    ys2= set(make_divisors(N))
    lst=[]
    for i in range(2,N+1):
        ans = check(N,i)
        if ans:
            lst.append((i,N%i,(N-1)%i))
    print(len(lst))

if __name__ == "__main__":
    sosou(int(input()))
    #resolve()
    #unittest.main()