[Python] pronic number check for N [closed]

Discussão em 'Python' iniciado por Stack, Dezembro 9, 2024.

  1. Stack

    Stack Membro Participativo

    The program must accept an integer N as the input. The program must print all the pronic integers formed by series of continuously occurring digits (in the same order) in N as the output.

    Note: The pronic integers must be printed in the order of their occurrence. The pronic integers can be represented as n*(n+1).

    Boundary Condition(s): 1 <= N <= 10^20

    Input Format: The first line contains N. Output Format: The first line contains the pronic integers separated by a space.

    Example Input/Output 1:

    Input: 93042861 Output: 930 30 0 42 2 6

    Explanation: 30 * 31 = 930 5 * 6 = 30 0 * 1 = 0 6 * 7 = 42 1 * 2 = 2 2 * 3 = 6

    Example Input/Output 2:

    Input: 247025123524 Output: 2 702 0 2 12 2 2352 2

    import math
    def is_pronic(number):
    if number==0:
    return True
    x=int(math.sqrt(number))
    return x*(x+1)==number
    def f_pronic_numbers(number):
    char=str(number)
    length=len(char)
    # pronic_number=[]
    for i in range(length):
    for j in range(i+1,length+1):
    if is_pronic(int(char[i:j])) and (char[i:j]==str(int(char[i:j]))):
    print(char[i:j],end=" ")

    n=int(input())
    f_pronic_numbers(n)


    for this only the 3 test case have been passed i dont whatt may be the 1 test case that failed

    Continue reading...

Compartilhe esta Página