giulio98/xlcost-single-prompt huggingface dataset:
# check if the given number is ore number or not | python3 program to check if the given number is ore number ; function that returns harmonic mean ; note that this loop runs till square root ; if divisors are equal , store 'i ; otherwise store ' i ' and ' n / i ' both ; utility function to calculate harmonic mean of the divisors ; declare sum variables and initialize with zero . ; calculate denominator ; calculate harmonic mean and return ; function to check if a number is ore number ; calculate harmonic mean of divisors of n ; check if harmonic mean is an integer or not ; 

arr = []


def generateDivisors(n):
    for i in range(1, int(n**(0.5)) + 1):
        if n % i == 0:
            if n // i == i:
                arr.append(i)
            else:
                arr.append(i)
                arr.append(n // i)


def harmonicMean(n):

    generateDivisors(n)
    Sum = 0
    length = len(arr)
    for i in range(0, length):
        Sum = Sum + (n / arr[i])

    Sum = Sum / n
    return length / Sum


def isOreNumber(n):
    mean = harmonicMean(n)
    if mean - int(mean) == 0:
        return True
    else:
        return False


if __name__ == "__main__":

    n = 28

    if isOreNumber(n) == True:
        print("YES")
    else:
        print("NO")

# Expected output:
YES
# area of a square inscribed in a circle which is inscribed in a hexagon | python 3 program to find the area of the square inscribed within the circle which in turn is inscribed in a hexagon ; function to find the area of the square ; side of hexagon cannot be negative ; area of the square ; 

from math import pow, sqrt


def area(a):
    if (a < 0):
        return -1
    area = pow((a * sqrt(3)) / (sqrt(2)), 2)
    return area


if __name__ == '__main__':
    a = 5
    print("{0:.3}".format(area(a)))

# Expected output:
37.5
# program to find nth term of series 1 , 6 , 17 , 34 , 56 , 86 , 121 , 162 , ... ... . | calculate nth term of series ; 
def nthTerm(n):
    return 3 * pow(n, 2) - 4 * n + 2


N = 4
print(nthTerm(N))

# Expected output:
34
# Sum of the first N terms of the series 2 , 10 , 30 , 68 , ... . | Function to calculate the sum ; number of terms to be included in the sum ; find the Sum
def calculateSum(n):
    return (n * (n + 1) // 2 + pow((n * (n + 1) // 2), 2))


n = 3
print("Sum = ", calculateSum(n))

# Expected output:
Sum =  42
# check if two arrays are permutations of each other using mathematical operation | function to check if arrays are permutations of each other ; calculating sum and multiply of first array ; calculating sum and multiply of second array ; if sum and mul of both arrays are equal , return true , else return false . ; 
def arePermutations(a, b, n, m):
    sum1, sum2, mul1, mul2 = 0, 0, 1, 1
    for i in range(n):
        sum1 += a[i]
        mul1 *= a[i]
    for i in range(m):
        sum2 += b[i]
        mul2 *= b[i]
    return ((sum1 == sum2) and (mul1 == mul2))


if __name__ == "__main__":
    a = [1, 3, 2]
    b = [3, 1, 2]
    n = len(a)
    m = len(b)
    if arePermutations(a, b, n, m):
        print("Yes")
    else:
        print("No")

# Expected output:
Yes
# program to find the head start in a race | function to find the b start to c ; when b completed it 's 100 meter  then completed meters by c is ; 
def Race(B, C):
    result = 0
    result = ((C * 100) // B)
    return 100 - result


if __name__ == "__main__":
    B = 10
    C = 28
    B = 100 - B
    C = 100 - C
    print(str(Race(B, C)) + " meters")

# Expected output:
20 meters
# minimum time required to fill a cistern using n pipes | function to calculate the time ; 
def Time(arr, n, Emptypipe):
    fill = 0
    for i in range(0, n):
        fill += (1 / arr[i])
    fill = fill - (1 / float(Emptypipe))
    return int(1 / fill)


if __name__ == '__main__':
    arr = [12, 14]
    Emptypipe = 30
    n = len(arr)
    print((Time(arr, n, Emptypipe)), "Hours")

# Expected output:
8 Hours
# check if decimal representation of an octal number is divisible by 7 | function to check divisibility ; sum of all individual digits ; condition ; 
def check(n):
    sum = 0
    while n != 0:
        sum += n % 10
        n = n // 10
    if sum % 7 == 0:
        return 1
    else:
        return 0


if __name__ == "__main__":
    n = 25
    print(("YES")if check(n) == 1 else print("NO"))

# Expected output:
YES
# sum of all the prime divisors of a number | python 3 program to find sum of prime divisors of n ; function to check if the number is prime or not . ; corner cases ; this is checked so that we can skip middle five numbers in below loop ; function to find sum of prime divisors of n ; 

N = 1000005


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 SumOfPrimeDivisors(n):
    sum = 0
    for i in range(1, n + 1):
        if n % i == 0:
            if isPrime(i):
                sum += i
    return sum


n = 60
print("Sum of prime divisors of 60 is " + str(SumOfPrimeDivisors(n)))

# Expected output:
Sum of prime divisors of 60 is 10
# sum of all the prime divisors of a number | function to find prime divisors of all numbers from 1 to n ; if the number is prime ; add this prime to all it 's multiples ; 
def Sum(N):
    SumOfPrimeDivisors = [0] * (N + 1)
    for i in range(2, N + 1):
        if (SumOfPrimeDivisors[i] == 0):
            for j in range(i, N + 1, i):
                SumOfPrimeDivisors[j] += i
    return SumOfPrimeDivisors[N]


N = 60
print("Sum of prime", "divisors of 60 is", Sum(N))

# Expected output:
Sum of prime divisors of 60 is 10
# find ( a ^ b ) % m where ' b ' is very large | function to find power ; update x if it is more than or equal to p ; if y is odd , multiply x with the result ; y must be even now y = y >> 1 y = y / 2 ; 
def power(x, y, p):
    res = 1
    x = x % p

    while (y > 0):
        if (y & 1):
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p

    return res


a = 3

b = "100000000000000000000000000"

remainderB = 0
MOD = 1000000007
for i in range(len(b)):
    remainderB = ((remainderB * 10 +
                   ord(b[i]) - 48) %
                  (MOD - 1))

print(power(a, remainderB, MOD))

# Expected output:
835987331
# squares of numbers with repeated single digits | set 1 ( 3 , 6 and 9 ) | function to find the square of 333. . .333 , 666. . .666 and 999. . .999 ; if the number is 333. . .333 ; if the number is 666. . .666 ; if the number is 999. . .999 ; variable for hold result ; find the no of digit ; add size - 1 time a in result ; add one time b in result ; add size - 1 time c in result ; add one time d in result ; return result ; 
def find_Square_369(num):
    if (num[0] == '3'):
        a = '1'
        b = '0'
        c = '8'
        d = '9'
    elif (num[0] == '6'):
        a = '4'
        b = '3'
        c = '5'
        d = '6'
    else:
        a = '9'
        b = '8'
        c = '0'
        d = '1'
    result = ""
    size = len(num)
    for i in range(1, size):
        result += a
    result += b
    for i in range(1, size):
        result += c
    result += d
    return result


num_3 = "3333"
num_6 = "6666"
num_9 = "9999"
result = ""
result = find_Square_369(num_3)
print("Square of " + num_3 + " is : " + result)
result = find_Square_369(num_6)
print("Square of " + num_6 + " is : " + result)
result = find_Square_369(num_9)
print("Square of " + num_9 + " is : " + result)

# Expected output:
Square of 3333 is : 11108889
Square of 6666 is : 44435556
Square of 9999 is : 99980001
# ways to multiply n elements with an associative operation | function to find the required factorial ; function to find ncr ; function to find the number of ways ; 
def fact(n):
    if (n == 0 or n == 1):
        return 1
    ans = 1
    for i in range(1, n + 1):
        ans = ans * i
    return ans


def nCr(n, r):
    Nr = n
    Dr = 1
    ans = 1
    for i in range(1, r + 1):
        ans = int((ans * Nr) / (Dr))
        Nr = Nr - 1
        Dr = Dr + 1
    return ans


def solve(n):
    N = 2 * n - 2
    R = n - 1
    return (nCr(N, R) * fact(n - 1))


n = 6
print(solve(n))

# Expected output:
30240
# pythagorean triplet with given sum | python3 program to find pythagorean triplet of given sum . ; considering triplets in sorted order . the value of first element in sorted triplet can be at - most n / 3. ; the value of second element must be less than equal to n / 2 ; 
def pythagoreanTriplet(n):
    for i in range(1, int(n / 3) + 1):
        for j in range(i + 1, int(n / 2) + 1):
            k = n - i - j
            if (i * i + j * j == k * k):
                print(i, ", ", j, ", ", k, sep="")
                return
    print("No Triplet")


n = 12
pythagoreanTriplet(n)

# Expected output:
3, 4, 5
# program to print binomial expansion series | function to calculate factorial of a number ; function to print the series ; calculating the value of n ! ; loop to display the series ; for calculating the value of ncr ; calculating the value of a to the power k and x to the power k ; display the series ; 
def factorial(n):
    f = 1
    for i in range(2, n + 1):
        f *= i
    return f


def series(A, X, n):
    nFact = factorial(n)
    for i in range(0, n + 1):
        niFact = factorial(n - i)
        iFact = factorial(i)
        aPow = pow(A, n - i)
        xPow = pow(X, i)
        print(int((nFact * aPow * xPow) / (niFact * iFact)), end=" ")


A = 3
X = 4
n = 5
series(A, X, n)

# Expected output:
243 1620 4320 5760 3840 1024
# sum of series with alternate signed squares of ap | function to calculate series sum ; 
def seiresSum(n, a):
    res = 0
    for i in range(0, 2 * n):
        if (i % 2 == 0):
            res += a[i] * a[i]
        else:
            res -= a[i] * a[i]
    return res


n = 2
a = [1, 2, 3, 4]
print(seiresSum(n, a))

# Expected output:
-10
# power of a prime number ‘ r ’ in n ! | function to return power of a no . ' r ' in factorial of n ; keep dividing n by powers of ' r ' and update count ; 
def power(n, r):
    count = 0
    i = r
    while ((n / i) >= 1):
        count += n / i
        i = i * r
    return int(count)


n = 6
r = 3
print(power(n, r))

# Expected output:
2
# average of first n odd naturals numbers | returns the avg of first n odd numbers ; sum of first n odd number ; average of first n odd numbers ; 
def avg_of_odd_num(n):
    sm = 0
    for i in range(0, n):
        sm = sm + (2 * i + 1)
    return sm // n


n = 20
print(avg_of_odd_num(n))

# Expected output:
20
# average of first n odd naturals numbers | return the average of sum of first n odd numbers ; 
def avg_of_odd_num(n):
    return n


n = 8
print(avg_of_odd_num(n))

# Expected output:
8
# program to print fibonacci triangle | function to fill fibonacci numbers in f [ ] ; 1 st and 2 nd number of the series are 1 and 1 ; add the previous 2 numbers in the series and store it ; fill fibonacci numbers in f [ ] using fib ( ) . we need n = n * ( n + 1 ) / 2 fibonacci numbers to make a triangle of height n ; to store next fibonacci number to print ; for loop to keep track of number of lines ; for loop to keep track of numbers in each line ; 
def fib(f, N):
    f[1] = 1
    f[2] = 1
    for i in range(3, N + 1):
        f[i] = f[i - 1] + f[i - 2]


def fiboTriangle(n):
    N = n * (n + 1) // 2
    f = [0] * (N + 1)
    fib(f, N)
    fiboNum = 1
    for i in range(1, n + 1):
        for j in range(1, i + 1):
            print(f[fiboNum], " ", end="")
            fiboNum = fiboNum + 1
        print()


n = 5
fiboTriangle(n)

# Expected output:
1  
1  2  
3  5  8  
13  21  34  55  
89  144  233  377  610
# average of odd numbers till a given odd number | function to calculate the average of odd numbers ; count odd numbers ; store the sum of odd numbers ; 
def averageOdd(n):
    if (n % 2 == 0):
        print("Invalid Input")
        return -1
    sm = 0
    count = 0
    while (n >= 1):
        count = count + 1
        sm = sm + n
        n = n - 2
    return sm // count


n = 15
print(averageOdd(n))

# Expected output:
8
# average of odd numbers till a given odd number | function to calculate the average of odd numbers ; 
def averageOdd(n):
    if (n % 2 == 0):
        print("Invalid Input")
        return -1
    return (n + 1) // 2


n = 15
print(averageOdd(n))

# Expected output:
8
# find max of two rational numbers | python program to find max between two rational numbers ; get lcm of two number 's ; get max rational number ; find the lcm of first -> denominator and sec -> denominator ; declare nume1 and nume2 for get the value of first numerator and second numerator ; 

import math


def lcm(a, b):
    return (a * b) // (math .gcd(a, b))


def maxRational(first, sec):
    k = lcm(first[1], sec[1])
    nume1 = first[0]
    nume2 = sec[0]
    nume1 *= k // (first[1])
    nume2 *= k // (sec[1])
    return first if (nume2 < nume1)else sec


first = [3, 2]
sec = [3, 4]
res = maxRational(first, sec)
print(res[0], "/", res[1], sep="")

# Expected output:
3/2
# trinomial triangle | function to find the trinomial triangle value . ; base case ; base cas ; recursive step . ; function to print trinomial triangle of height n . ; printing n rows . ; printing first half of triangle ; printing second half of triangle . ; 
def TrinomialValue(n, k):
    if n == 0 and k == 0:
        return 1
    if k < -n or k > n:
        return 0
    return (
        TrinomialValue(
            n -
            1,
            k -
            1) +
        TrinomialValue(
            n -
            1,
            k) +
        TrinomialValue(
            n -
            1,
            k +
            1))


def printTrinomial(n):
    for i in range(n):
        for j in range(-i, 1):
            print(TrinomialValue(i, j), end=" ")
        for j in range(1, i + 1):
            print(TrinomialValue(i, j), end=" ")
        print("", end='')


n = 4
printTrinomial(n)

# Expected output:
1 1 1 1 1 2 3 2 1 1 3 6 7 6 3 1
# trinomial triangle | function to find the trinomial triangle value . ; using property of trinomial triangle . ; if value already calculated , return that . ; base case ; base case ; recursive step and storing the value . ; function to print trinomial triangle of height n . ; printing n rows . ; printing first half of triangle ; printing second half of triangle . ; 
def TrinomialValue(dp, n, k):
    if k < 0:
        k = -k
    if dp[n][k] != 0:
        return dp[n][k]
    if n == 0 and k == 0:
        return 1
    if k < -n or k > n:
        return 0
    return (
        TrinomialValue(
            dp,
            n -
            1,
            k -
            1) +
        TrinomialValue(
            dp,
            n -
            1,
            k) +
        TrinomialValue(
            dp,
            n -
            1,
            k +
            1))


def printTrinomial(n):
    dp = [[0] * 10] * 10
    for i in range(n):
        for j in range(-i, 1):
            print(TrinomialValue(dp, i, j), end=" ")
        for j in range(1, i + 1):
            print(TrinomialValue(dp, i, j), end=" ")
        print("", end='')


n = 4
printTrinomial(n)

# Expected output:
1 1 1 1 1 2 3 2 1 1 3 6 7 6 3 1
# sum of largest prime factor of each number less than equal to n | function to find sum of largest prime factor of each number less than equal to n ; create an integer array " prime [ 0 . . n ] " and initialize all entries of it as 0. a value in prime [ i ] will finally be 0 if ' i ' is a prime , else it will contain the largest prime factor of ' i ' . ; if prime [ p ] is '0' , then it is a prime number ; update all multiples of p ; sum up the largest prime factor of all the numbers ; if ' p ' is a non - prime number then prime [ p ] gives its largesr prime factor ; ' p ' is a prime number ; required sum ; 
def sumOfLargePrimeFactor(n):
    prime = [0] * (n + 1)
    sum = 0
    max = int(n / 2)
    for p in range(2, max + 1):
        if prime[p] == 0:
            for i in range(p * 2, n + 1, p):
                prime[i] = p
    for p in range(2, n + 1):
        if prime[p]:
            sum += prime[p]
        else:
            sum += p
    return sum


n = 12
print("Sum =", sumOfLargePrimeFactor(n))

# Expected output:
Sum = 46
# sum of multiples of a number up to n | calculates sum of multiples of a number upto n ; number of multiples ; sum of first m natural numbers ; sum of multiples ; 
def calculate_sum(a, N):
    m = N / a
    sum = m * (m + 1) / 2
    ans = a * sum
    print("Sum of multiples of ", a, " up to ", N, " = ", ans)


calculate_sum(7, 49)

# Expected output:
Sum of multiples of  7  up to  49  =  196.0
# given a huge number check if it 's a power of two. | returns 1 when str is power of 2 return 0 when str is not a power of 2 ; sum stores the intermediate dividend while dividing . ; if the input is "1" then return 0 because 2 ^ k = 1 where k >= 1 and here k = 0 ; divide the number until it gets reduced to 1 if we are successfully able to reduce the number to 1 it means input string is power of two if in between an odd number appears at the end it means string is not divisible by two hence not a power of 2. ; if the last digit is odd then string is not divisible by 2 hence not a power of two return 0. ; divide the whole string by 2. i is used to track index in current number . j is used to track index for next iteration . ; if num < 2 then we have to take another digit to the right of a [ i ] to make it bigger than a [ i ] . e . g . 214 / 2 -- > 107 ; if it 's not the first index. e.g 214  then we have to include 0. ; for eg . "124" we will not write 064 so if it is the first index just ignore ; after every division by 2 the length of string is changed . ; if the string reaches to 1 then the str is a power of 2. ; 
def isPowerOf2(sttr):
    len_str = len(sttr)
    sttr = list(sttr)
    num = 0
    if (len_str == 1 and sttr[len_str - 1] == '1'):
        return 0
    while (len_str != 1 or sttr[len_str - 1] != '1'):
        if ((ord(sttr[len_str - 1]) - ord('0')) % 2 == 1):
            return 0
        j = 0
        for i in range(len_str):
            num = num * 10 + (ord(sttr[i]) - ord('0'))
            if (num < 2):
                if (i != 0):
                    sttr[j] = '0'
                    j += 1
                continue
            sttr[j] = chr((num // 2) + ord('0'))
            j += 1
            num = (num) - (num // 2) * 2
        len_str = j
    return 1


str1 = "124684622466842024680246842024662202000002"
str2 = "1"
str3 = "128"
print("", isPowerOf2(str1), "", isPowerOf2(str2), "", isPowerOf2(str3))

# Expected output:
 0  0  1
# given a huge number check if it 's a power of two. | function to check whether a number is power of 2 or not ; 
def ispowerof2(num):
    if ((num & (num - 1)) == 0):
        return 1
    return 0


if __name__ == '__main__':
    num = 549755813888
    print(ispowerof2(num))

# Expected output:
1
# count divisors of array multiplication | to count number of factors in a number ; initialize count with 0 ; increment count for every factor of the given number x . ; return number of factors ; returns number of divisors in array multiplication ; multipliying all elements of the given array . ; calling function which count number of factors of the number ; 
def counDivisors(X):
    count = 0
    for i in range(1, X + 1):
        if (X % i == 0):
            count += 1
    return count


def countDivisorsMult(arr, n):
    mul = 1
    for i in range(n):
        mul *= arr[i]
    return counDivisors(mul)


arr = [2, 4, 6]
n = len(arr)
print(countDivisorsMult(arr, n))

# Expected output:
10
# count divisors of array multiplication | python 3 program to count divisors in array multiplication . ; create a boolean array " isprime [ 0 . . n ] " and initialize all entries it as true . a value in isprime [ i ] will finally be false if i is not a isprime , else true . ; if isprime [ p ] is not changed , then it is a isprime ; update all multiples of p ; print all isprime numbers ; returns number of divisors in array multiplication ; find all prime numbers smaller than the largest element . ; find counts of occurrences of each prime factor ; compute count of all divisors using counts prime factors . ; 

from collections import defaultdict


def SieveOfEratosthenes(largest, prime):
    isPrime = [True] * (largest + 1)
    p = 2
    while p * p <= largest:
        if (isPrime[p]):
            for i in range(p * 2, largest + 1, p):
                isPrime[i] = False
        p += 1
    for p in range(2, largest + 1):
        if (isPrime[p]):
            prime .append(p)


def countDivisorsMult(arr, n):
    largest = max(arr)
    prime = []
    SieveOfEratosthenes(largest, prime)
    mp = defaultdict(int)
    for i in range(n):
        for j in range(len(prime)):
            while (arr[i] > 1 and arr[i] % prime[j] == 0):
                arr[i] //= prime[j]
                mp[prime[j]] += 1
        if (arr[i] != 1):
            mp[arr[i]] += 1
    res = 1
    for it in mp .values():
        res *= (it + 1)
    return res


if __name__ == "__main__":
    arr = [2, 4, 6]
    n = len(arr)
    print(countDivisorsMult(arr, n))

# Expected output:
10
# k distant prime pairs in a given range | python3 program for the above approach ; function to generate prime numbers in the given range [ l , r ] ; store all value in the range ; erase 1 as its non - prime ; perform sieve of eratosthenes ; find current multiple ; erase as it is a non - prime ; increment multiple ; function to print all the prime pairs in the given range that differs by k ; generate all prime number ; traverse the map m ; if it . first & ( it . first + k ) is prime then print this pair ; 

from math import sqrt


def findPrimeNos(L, R, M):
    for i in range(L, R + 1):
        M[i] = M .get(i, 0) + 1
    if (1 in M):
        M .pop(1)
    for i in range(2, int(sqrt(R)) + 1, 1):
        multiple = 2
        while ((i * multiple) <= R):
            if ((i * multiple) in M):
                M .pop(i * multiple)
            multiple += 1


def getPrimePairs(L, R, K):
    M = {}
    findPrimeNos(L, R, M)
    for key, values in M .items():
        if ((key + K) in M):
            print("(", key, ",", key + K, ")", end=" ")


if __name__ == '__main__':
    L = 1
    R = 19
    K = 6
    getPrimePairs(L, R, K)

# Expected output:
( 5 , 11 ) ( 7 , 13 ) ( 11 , 17 ) ( 13 , 19 )
# enneacontahexagon numbers | function to find the nth enneacontahexagon number ; 
def EnneacontahexagonNum(n):
    return (94 * n * n - 92 * n) // 2


n = 3
print(EnneacontahexagonNum(n))

# Expected output:
285
# find two composite numbers such that there difference is n | function to find the two composite numbers ; 
def find_composite_nos(n):
    print(9 * n, 8 * n)


if __name__ == "__main__":
    n = 4
    find_composite_nos(n)

# Expected output:
36 32
# count the number of pairs ( i , j ) such that either arr [ i ] is divisible by arr [ j ] or arr [ j ] is divisible by arr [ i ] | function to find number of unordered pairs ; maximum element from the array ; array to store the frequency of each element ; stores the number of unordered pairs ; store the frequency of each element ; find the number of unordered pairs ; if the number j divisible by ith element is present in the array ; if the ith element of the array has frequency more than one ; 
def freqPairs(arr, n):
    max = arr[0]
    for i in range(len(arr)):
        if arr[i] > max:
            max = arr[i]
    freq = [0 for i in range(max + 1)]
    count = 0
    for i in range(n):
        freq[arr[i]] += 1
    for i in range(n):
        for j in range(2 * arr[i], max + 1, arr[i]):
            if (freq[j] >= 1):
                count += freq[j]
        if (freq[arr[i]] > 1):
            count += freq[arr[i]] - 1
            freq[arr[i]] -= 1
    return count


if __name__ == '__main__':
    arr = [3, 2, 4, 2, 6]
    n = len(arr)
    print(freqPairs(arr, n))

# Expected output:
6
# find the nth term of the series 1 + 2 + 6 + 15 + 31 + 56 + ... | calculate nth term of given series ; 
def Nth_Term(n):
    return (2 * pow(n, 3) - 3 * pow(n, 2) + n + 6) // 6


N = 8
print(Nth_Term(N))

# Expected output:
141