giulio98/xlcost-single-prompt huggingface dataset:
# second pentagonal numbers | function to find n - th term in the series ; 
def findNthTerm(n):
    print(n * (3 * n + 1) // 2, end=" ")


N = 4
findNthTerm(N)

# Expected output:
26
# idoneal numbers | function to check if number is an idoneal numbers ; iterate for all triples pairs ( a , b , c ) ; if the condition is satisfied ; 
def isIdoneal(n):
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            for c in range(b + 1, n + 1):
                if (a * b + b * c + c * a == n):
                    return False
    return True


N = 10
if (isIdoneal(N)):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# lynch | python3 implementation for the above approach ; function to check the divisibility of the number by its digit . ; if the digit divides the number then return true else return false . ; function to check if all digits of n divide it or not ; taking the digit of the number into digit var . ; function to check if n has all distinct digits ; create an array of size 10 and initialize all elements as false . this array is used to check if a digit is already seen or not . ; traverse through all digits of given number ; find the last digit ; if digit is already seen , return false ; mark this digit as seen ; remove the last digit from number ; function to check lynch - bell numbers ; 

import math


def checkDivisibility(n, digit):
    return ((digit != 0) and ((n % digit) == 0))


def isAllDigitsDivide(n):
    temp = n
    while (temp >= 1):
        digit = int(temp % 10)
        if (checkDivisibility(n, digit) == False):
            return 0
        temp = temp / 10
    return 1


def isAllDigitsDistinct(n):
    arr = [0] * 10
    while (n >= 1):
        digit = int(n % 10)
        if (arr[digit]):
            return 0
        arr[digit] = 1
        n = int(n / 10)
    return 1


def isLynchBell(n):
    return (isAllDigitsDivide(n) and isAllDigitsDistinct(n))


if __name__ == '__main__':
    N = 12
    if isLynchBell(N):
        print("Yes")
    else:
        print("No")

# Expected output:
Yes
# repunit numbers | function to check if a number contains all the digits 0 , 1 , . . , ( b - 1 ) an equal number of times ; to store number of digits of n in base b ; to count frequency of digit 1 ; condition to check three or more 1 's  and number of ones is equal to number  of digits of n in base b ; 
def isRepunitNum(n, b):
    length = 0
    countOne = 0
    while (n != 0):
        r = n % b
        length += 1
        if (r == 1):
            countOne += 1
        n = n // b
    return countOne >= 3 and countOne == length


if __name__ == '__main__':
    n = 31
    base = 2
    if (isRepunitNum(n, base)):
        print("Yes")
    else:
        print("No")

# Expected output:
Yes
# gapful numbers | python3 program for the above approach ; find the first digit ; find total number of digits - 1 ; find first digit ; return first digit ; find the last digit ; return the last digit ; a function to check gapful numbers ; return true if n is gapful number ; 

import math


def firstDigit(n):
    digits = math .log10(n)
    n = (n / math .pow(10, digits))
    return n


def lastDigit(n):
    return (n % 10)


def isGapful(n):
    concatenation = (firstDigit(n) * 10) + lastDigit(n)
    return (n % concatenation)


if __name__ == '__main__':
    n = 108
    if (isGapful(n)):
        print("Yes")
    else:
        print("No")

# Expected output:
Yes
# check if all objects of type a and b can be placed on n shelves | function to return if allocation is possible or not ; stores the shelves needed for items of type - a and type - b ; find number of shelves needed for items of type - a ; fill a / k shelves fully by the items of type - a ; otherwise ; fill a / l shelves fully and add remaining to an extra shelf ; find number of shelves needed for items of type - b ; fill b / l shelves fully by the items of type - b ; fill b / l shelves fully and add remaining to an an extra shelf ; total shelves needed ; if required shelves exceed n ; 
def isPossible(A, B, N, K, L):
    needa = 0
    needb = 0
    if (A % K == 0):
        needa = A // K
    else:
        needa = A // K + 1
    if (B % L == 0):
        needb = B // L
    else:
        needb = B // L + 1
    total = needa + needb
    if (total > N):
        return False
    else:
        return True


if __name__ == '__main__':
    A, B, N = 3, 3, 3
    K, M = 4, 2
    if (isPossible(A, B, N, K, M)):
        print('YES')
    else:
        print('NO')

# Expected output:
YES
# minimise n such that sum of count of all factors upto n is greater than or equal to x | python3 program for the above approach ; array to store smallest prime factors of each no . ; function to calculate smallest prime factor of n . ; marking spf [ j ] if it is not previously marked ; array to store the count of factor for n ; prefix array which contains the count of factors from 1 to n ; function to count total factors from 1 to n ; store total factors of i ; stores total factors from 1 to i ; function to search lowest x such that the given condition is satisfied ; find mid ; search in the right half ; search in the left half ; return the position after binary search ; function to find the required sum ; precompute smallest prime factor of each value ; calculate count of total factors from 1 to n ; binary search to find minimum n ; 

MAX = 1000050
spf = [0 for i in range(MAX + 1)]
tfactor = [0 for i in range(MAX + 1)]
pre = [0 for i in range(MAX + 1)]


def calculate_SPF():
    for i in range(MAX + 1):
        spf[i] = i
    for i in range(4, MAX + 1, 2):
        spf[i] = 2
    i = 3
    while (i * i <= MAX):
        if (spf[i] == i):
            j = i * i
            while (j <= MAX):
                if (spf[j] == j):
                    spf[j] = i
                j += i
        i += 1


def CountTotalfactors():
    tfactor[1] = pre[1] = 1
    for i in range(2, MAX + 1):
        mspf = spf[i]
        prim = mspf
        temp = i
        cnt = 0
        while (temp % mspf == 0):
            temp //= mspf
            cnt += 1
            prim = prim * mspf
        tfactor[i] = (cnt + 1)*tfactor[temp]
        pre[i] = pre[i - 1]+tfactor[i]


def BinarySearch(X):
    start = 1
    end = MAX - 1
    while (start < end):
        mid = (start + end) // 2
        if (pre[mid] == X):
            return mid
        elif (pre[mid] < X):
            start = mid + 1
        else:
            end = mid
    return start


def findSumOfCount(X):
    calculate_SPF()
    CountTotalfactors()
    print(BinarySearch(X))


if __name__ == "__main__":
    X = 10
    findSumOfCount(X)

# Expected output:
5
# how to calculate the easter date for a given year using gauss ' algorithm | python3 program for the above approach ; function calculates and prints easter date for given year y ; all calculations done on the basis of gauss easter algorithm ; a corner case , when d is 29 ; another corner case , when d is 28 ; if days > 31 , move to april april = 4 th month ; otherwise , stay on march march = 3 rd month ; 

import math


def gaussEaster(Y):
    A = Y % 19
    B = Y % 4
    C = Y % 7
    P = math .floor(Y / 100)
    Q = math .floor((13 + 8 * P) / 25)
    M = (15 - Q + P - P // 4) % 30
    N = (4 + P - P // 4) % 7
    D = (19 * A + M) % 30
    E = (2 * B + 4 * C + 6 * D + N) % 7
    days = (22 + D + E)
    if ((D == 29) and (E == 6)):
        print(Y, "-04-19")
        return
    elif ((D == 28) and (E == 6)):
        print(Y, "-04-18")
        return
    else:
        if (days > 31):
            print(Y, "-04-", (days - 31))
            return
        else:
            print(Y, "-03-", days)
            return


Y = 2020
gaussEaster(Y)

# Expected output:
2020 -04- 12
# place value of a 
def placeValue(N, num):
    total = 1
    value = 0
    rem = 0
    while (True):
        rem = N % 10
        N = N // 10
        if (rem == num):
            value = total * rem
            break
        total = total * 10
    return value


D = 5
N = 85932
print(placeValue(N, D))

# Expected output:
5000
# super | python3 implementation to check if n is a super poulet number ; function to find the divisors ; loop to iterate over the square root of the n ; check if divisors are equal ; function to check if n is a super poulet number ; loop to check that every divisor divides 2 ^ d - 2 ; 

import math


def findDivisors(n):
    divisors = []
    for i in range(1, int(math .sqrt(n) + 1)):
        if (n % i == 0):
            if (n / i == i):
                divisors .append(i)
            else:
                divisors .append(i)
                divisors .append(int(n / i))
    return sorted(divisors)


def isSuperdNum(n):
    d = findDivisors(n)
    for i in d:
        x = (2 ** i - 2) / i
        if int(x) != x:
            return False
    return True


if __name__ == "__main__":
    n = 341
    if isSuperdNum(n):
        print("Yes")
    else:
        print("No")

# Expected output:
Yes
# beatty sequence | python3 implementation of the above approach ; function to print the first n terms of the beatty sequence ; 

import math


def BeattySequence(n):
    for i in range(1, n + 1):
        ans = math .floor(i * math .sqrt(2))
        print(ans, end=', ')


n = 5
BeattySequence(n)

# Expected output:
1, 2, 4, 5, 7,
# sum of the first n pronic numbers | function to calculate the sum ; 
def calculateSum(N):
    return (N * (N - 1) // 2 + N * (N - 1) * (2 * N - 1) // 6)


N = 3
print(calculateSum(N))

# Expected output:
8
# self numbers | function to find the sum of digits of a number n ; function to check for self number ; 
def getSum(n):
    sum1 = 0
    while (n != 0):
        sum1 = sum1 + n % 10
        n = n // 10
    return sum1


def isSelfNum(n):
    for m in range(1, n + 1):
        if (m + getSum(m) == n):
            return False
    return True


n = 20
if (isSelfNum(n)):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# central binomial coefficient | function to find the value of nth central binomial coefficient ; calculate value of binomial coefficient in bottom up manner ; base cases ; calculate value using previously stored values ; 
def binomialCoeff(n, k):
    C = [[0 for j in range(k + 1)]for i in range(n + 1)]
    i = 0
    j = 0
    for i in range(n + 1):
        for j in range(min(i, k) + 1):
            if j == 0 or j == i:
                C[i][j] = 1
            else:
                C[i][j] = (C[i - 1][j - 1] + C[i - 1][j])
    return C[n][k]


if __name__ == '__main__':
    n = 3
    k = n
    n = 2 * n
    print(binomialCoeff(n, k))

# Expected output:
20
# multiply perfect number | python3 implementation of the above approach ; function to find the sum of divisors ; note that this loop runs till square root of n ; if divisors are equal , take only one of them ; otherwise take both ; function to check multiply - perfect number ; 

import math


def getSum(n):
    sum1 = 0
    for i in range(1, int(math .sqrt(n))):
        if (n % i == 0):
            if (n // i == i):
                sum1 = sum1 + i
            else:
                sum1 = sum1 + i
                sum1 = sum1 + (n // i)
    return sum1


def MultiplyPerfectNumber(n):
    if (getSum(n) % n == 0):
        return True
    else:
        return False


n = 28
if (MultiplyPerfectNumber(n)):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# perfect totient number | function to find the totient number of the given value ; initialize result as n ; consider all prime factors of n and subtract their multiples from result ; check if p is a prime factor . ; if yes , then update n and result ; if n has a prime factor greater than sqrt ( n ) ( there can be at - most one such prime factor ) ; function to check if the number is a perfect totient number ; store original value of n ; loop to calculate sum of iterated totients ; condition for perfect totient number ; 
def phi(n):
    result = n
    for p in range(2, n):
        if p * p > n:
            break
        if (n % p == 0):
            while (n % p == 0):
                n //= p
            result -= result // p
    if (n > 1):
        result -= result // n
    return result


def isPerfectTotientNum(n):
    temp = n
    sum = 0
    while (n > 1):
        sum = sum + phi(n)
        n = phi(n)
    if (sum == temp):
        return True
    return False


if __name__ == '__main__':
    n = 9
    if (isPerfectTotientNum(n)):
        print("Yes")
    else:
        print("No")

# Expected output:
Yes
# cunningham numbers | python3 implementation for the above approach ; function to check if a number can be expressed as a ^ b . ; function to check if n is a cunningham number ; 

import math


def isPower(a):
    if (a == 1):
        return True
    i = 2
    while (i * i <= a):
        val = math .log(a) / math .log(i)
        if ((val - int(val)) < 0.00000001):
            return True
        i += 1
    return False


def isCunningham(n):
    return isPower(n - 1) or isPower(n + 1)


n = 126
if (isCunningham(n)):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# product of all subarrays of an array | set 2 | function to find the product of elements of all subarray ; initialize the result ; computing the product of subarray using formula ; return the product of all elements of each subarray ; 
def SubArrayProdct(arr, n):
    result = 1
    for i in range(0, n):
        result *= pow(arr[i], (i + 1) * (n - i))
    return result


arr = [2, 4]
N = len(arr)
print(SubArrayProdct(arr, N))

# Expected output:
64
# number of ways to reach ( m , n ) in a matrix starting from the origin without visiting ( x , y ) | function for computing ncr ; function to find factorial of a number ; function for counting the number of ways to reach ( m , n ) without visiting ( x , y ) ; 
def nCr(n, r):
    return (fact(n) // (fact(r) * fact(n - r)))


def fact(n):
    res = 1
    for i in range(2, n + 1):
        res = res * i
    return res


def countWays(m, n, x, y):
    return (nCr(m + n, m) - nCr(x + y, x) * nCr(m + n - x - y, m - x))


m = 5
n = 4
x = 3
y = 2
print(countWays(m, n, x, y))

# Expected output:
66
# smallest number greater than or equal to n using only digits 1 to k | function to count the digits greater than k ; function to print the list ; function to find the number greater than or equal to n , which is only made of first k digits ; if the number itself satisfy the conditions ; check digit from back ; if digit > k is present previously and current digit is less than k ; if current digit is greater than k ; if an extra digit needs to be added ; print the number ; 
def CountGreater(n, k):
    a = 0
    while (n > 0):
        if ((n % 10) > k):
            a += 1
        n = n // 10
    return a


def PrintList(ans):
    for i in ans:
        print(i, end='')


def getNumber(n, k):
    count = CountGreater(n, k)
    if (count == 0):
        print(n)
        return
    ans = []
    changed = False
    while (n > 0):
        digit = n % 10
        if (changed):
            ans .insert(0, digit)
        else:
            if (count == 0 and digit < k):
                ans .insert(0, digit + 1)
                changed = True
            else:
                ans .insert(0, 1)
                if (digit > k):
                    count -= 1
        n = n // 10
    if (changed == False):
        ans .insert(0, 1)
    PrintList(ans)
    return


N = 51234
K = 4
getNumber(N, K)

# Expected output:
111111
# find the batting average of a batsman | function to find the average of a batsman ; calculate number of dismissals ; check for 0 times out ; calculate batting average ; 
def averageRuns(runs, matches, notout):
    out = matches - notout
    if (out == 0):
        return -1
    avg = runs // out
    return avg


runs = 10000
matches = 250
notout = 50
avg = averageRuns(runs, matches, notout)
if (avg == -1):
    print("NA")
else:
    print(avg)

# Expected output:
50
# sum of series formed by difference between product and sum of n natural numbers | recursive function to calculate the sum upto nth term ; if n - th term is calculated ; update multi to store product upto k ; update add to store sum upto k ; update prevsum to store sum upto k ; proceed to next k ; function to calculate and return the sum upto nth term ; recursive function ; 
def seriesSumUtil(k, n, prevSum, multi, add):
    if (k == n + 1):
        return prevSum
    multi = multi * k
    add = add + k
    prevSum = prevSum + multi - add
    return seriesSumUtil(k + 1, n, prevSum, multi, add)


def seriesSum(n):
    if (n == 1):
        return 0
    prevSum = 0
    multi = 1
    add = 1
    return seriesSumUtil(2, n, prevSum, multi, add)


if __name__ == '__main__':
    N = 5
    print(seriesSum(N))

# Expected output:
118
# count of total bits toggled / flipped in binary representation of 0 to n | function to count and pr the required number of toggles ; store the count of toggles ; add the contribution of the current lsb ; update n ; print the result ; 
def solve(N):
    ans = 0
    while (N != 0):
        ans += N
        N //= 2
    print(ans)


N = 5
solve(N)

# Expected output:
8
# maximum bitwise and pair ( x , y ) from given range such that x and y can be same | function to return the maximum bitwise and ; 
def maximumAND(L, R):
    return R


if __name__ == '__main__':
    l = 3
    r = 7
    print(maximumAND(l, r))

# Expected output:
7
# check if k distinct array elements form an odd sum | function to return if odd sum is possible or not ; stores distinct odd elements ; stores distinct even elements ; iterating through given array ; if element is even ; if element is odd ; if atleast k elements in the array are odd ; check for all odd frequencies of odd elements whether sufficient even numbers are present or not ; count of even numbers required ; if required even numbers are present in the array ; 
def oddSum(A, N, K):
    Odd = set([])
    Even = set([])
    for i in range(N):
        if (A[i] % 2 == 0):
            Even .add(A[i])
        else:
            Odd .add(A[i])
    if (len(Odd) >= K):
        return True
    flag = False
    for i in range(1, K, 2):
        needed = K - i
        if (needed <= len(Even)):
            return True
    return flag


if __name__ == "__main__":
    K = 5
    A = [12, 1, 7, 7, 26, 18]
    N = 3
    if (oddSum(A, N, K)):
        print("YES")
    else:
        print("NO")

# Expected output:
NO
# count of elements not divisible by any other elements of array | function to count the number of elements of array which are not divisible by any other element of same array ; length for boolean array ; hash map for storing the element and it 's frequency ; update the maximum element ; boolean array of size of the max element + 1 ; marking the multiples as false ; to store the final count ; traverse boolean array ; check if i is not divisible by any other array elements and appears in the array only once ; return the final count ; 
def countEle(a, n):
    len = 0
    hmap = {}
    for i in range(n):
        len = max(len, a[i])
        hmap[a[i]] = hmap .get(a[i], 0) + 1
    v = [True for i in range(len + 1)]
    for i in range(n):
        if (v[a[i]] == False):
            continue
        for j in range(2 * a[i], len + 1, a[i]):
            v[j] = False
    count = 0
    for i in range(1, len + 1):
        if (v[i] and (i in hmap) and hmap[i] == 1):
            count += 1
    return count


if __name__ == '__main__':
    arr = [86, 45, 18, 4, 8, 28, 19, 33, 2]
    n = len(arr)
    print(countEle(arr, n))

# Expected output:
4
# smallest n digit number divisible by n | function to find the smallest n - digit number divisible by n ; find largest n digit number ; find smallest n digit number ; if i is divisible by n , then print i and return ; ; 
def smallestNumber(N):
    L = pow(10, N) - 1
    S = pow(10, N - 1)
    for i in range(S, L):
        if (i % N == 0):
            print(i)
            return


if __name__ == "__main__":
    N = 2
    smallestNumber(N)

# Expected output:
10
# number less than equals to n with maximum product of prime factors | function to find the smallest number having a maximum product of prime factors ; declare the list arr ; initialise list with 1 ; iterate from [ 2 , n ] ; if value at index i is 1 , then i is prime and make update list at index for all multiples of i ; initialise maxvalue ; find number having maximum product of prime factor <= n ; find the maximum value ; 
def maxPrimefactorNum(N):
    arr = []
    for i in range(N + 1):
        arr .append(1)
    for i in range(2, N + 1):
        if (arr[i] == 1):
            for j in range(i, N + 1, i):
                arr[j] *= i
    maxValue = 1
    for i in range(2, N + 1):
        if (arr[i] > maxValue):
            maxValue = i
    return maxValue


N = 20
print(maxPrimefactorNum(N))

# Expected output:
19
# zuckerman numbers | function to get product of digits ; function to check if n is an zuckerman number ; 
def getProduct(n):
    product = 1
    while (n > 0):
        product = product * (n % 10)
        n = n // 10
    return product


def isZuckerman(n):
    return n % getProduct(n) == 0


N = 115
if (isZuckerman(N)):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# additive prime number | check if n is prime or not ; corner cases ; this is checked to skip middle five numbers ; function to get sum of digits ; return the sum of digits ; function to check whether the given number is additive prime number or not ; if number is not prime ; check if sum of digits is prime or not ; 
def isPrime(n):
    if (n <= 1):
        return False
    if (n <= 3):
        return True
    if (n % 2 == 0 or n % 3 == 0):
        return False
    i = 5
    while (i * i <= n):
        if (n % i == 0 or n % (i + 2) == 0):
            return False
        i = i + 6
    return True


def getSum(n):
    sum = 0
    while (n != 0):
        sum = sum + n % 10
        n = n / 10
    return sum


def isAdditivePrime(n):
    if (not isPrime(n)):
        return False
    return isPrime(getSum(n))


N = 23
if (isAdditivePrime(N)):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# straight | function to check if n is a straight line number or not ; n must be > 99 ; difference between consecutive digits must be same ; 
def isStraighLineNum(N):
    if (N <= 99):
        return False
    str1 = str(N)
    d = int(str1[1]) - int(str1[0])
    for i in range(2, len(str1)):
        if (int(str1[i]) - int(str1[i - 1]) != d):
            return False
    return True


N = 135
if (isStraighLineNum(N)):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# second | function to find n - th term in the series ; 
def findNthTerm(n):
    print(pow(2, n) - 2 * n)


N = 4
findNthTerm(N)

# Expected output:
8
# alternating numbers | function to check if a string is of the form even odd even odd ... ; function to check if a string is of the form odd even odd even ... ; function to check if n is an alternating number ; 
def isEvenOddForm(s):
    n = len(s)
    for i in range(n):
        if (i % 2 == 0 and int(s[i]) % 2 != 0):
            return False
        if (i % 2 == 1 and int(s[i]) % 2 != 1):
            return False
    return True


def isOddEvenForm(s):
    n = len(s)
    for i in range(n):
        if (i % 2 == 0 and int(s[i]) % 2 != 1):
            return False
        if (i % 2 == 1 and int(s[i]) % 2 != 0):
            return False
    return True


def isAlternating(n):
    s = str(n)
    return (isEvenOddForm(s) or isOddEvenForm(s))


N = 129
if (isAlternating(N)):
    print("Yes")
else:
    print("No")

# Expected output:
Yes