giulio98/xlcost-single-prompt huggingface dataset:
# find the k | python3 program to find the k - th smallest factor ; function to find the k 'th divisor ; initialize vectors v1 and v2 ; store all the divisors in the two vectors accordingly ; reverse the vector v2 to sort it in increasing order ; if k is greater than the size of vectors then no divisor can be possible ; else print the ( k - 1 ) th value of vector ; if k is lying in first vector ; if k is lying in second vector ; 

import math as mt


def findkth(n, k):
    v1 = list()
    v2 = list()
    for i in range(1, mt .ceil(n ** (.5))):
        if (n % i == 0):
            v1 .append(i)
            if (i != mt .ceil(mt .sqrt(n))):
                v2 .append(n // i)
    v2[::-1]
    if (k > (len(v1) + len(v2))):
        print("Doesn't Exist", end="")
    else:
        if (k <= len(v1)):
            print(v1[k - 1])
        else:
            print(v2[k - len(v1) - 1])


n = 15
k = 2
findkth(n, k)

# Expected output:
3
# number of solutions for x < y , where a <= x <= b and c <= y <= d and x , y are integers | function to find the number of solutions for x < y , where a <= x <= b and c <= y <= d and x , y integers . ; to store answer ; iterate explicitly over all possible values of x ; return answer ; 
def NumberOfSolutions(a, b, c, d):
    ans = 0
    for i in range(a, b + 1):
        if d >= max(c, i + 1):
            ans += d - max(c, i + 1) + 1
    return ans


if __name__ == "__main__":
    a, b, c, d = 2, 3, 3, 4
    print(NumberOfSolutions(a, b, c, d))

# Expected output:
3
# minimum value possible of a given function from the given set | function to find the value of f ( n ) ; 
def findF_N(n):
    ans = 0
    for i in range(n):
        ans = ans + (i + 1) * (n - i - 1)
    return ans


n = 3
print(findF_N(n))

# Expected output:
4
# find n digits number which is divisible by d | function to return n digits number which is divisible by d ; to store answer ; 
def findNumber(n, d):
    ans = ""
    if (d != 10):
        ans += str(d)
        for i in range(1, n):
            ans += '0'
    else:
        if (n == 1):
            ans += "Impossible"
        else:
            ans += '1'
            for i in range(1, n):
                ans += '0'
    return ans


if __name__ == "__main__":
    n = 12
    d = 3
    print(findNumber(n, d))

# Expected output:
300000000000
# Count all the numbers less than 10 ^ 6 whose minimum prime factor is N | Python3 implementation of above approach ; the sieve of prime number and count of minimum prime factor ; form the prime sieve ; 1 is not a prime number ; form the sieve ; if i is prime ; if i is the least prime factor ; mark the number j as non prime ; count the numbers whose least prime factor is i ; form the sieve ; display ; display

MAX = 1000000
sieve_Prime = [0 for i in range(MAX + 4)]
sieve_count = [0 for i in range(MAX + 4)]


def form_sieve():
    sieve_Prime[1] = 1
    for i in range(2, MAX + 1):
        if sieve_Prime[i] == 0:
            for j in range(i * 2, MAX + 1, i):
                if sieve_Prime[j] == 0:
                    sieve_Prime[j] = 1
                    sieve_count[i] += 1


form_sieve()
n = 2
print("Count =", sieve_count[n] + 1)
n = 3
print("Count =", sieve_count[n] + 1)

# Expected output:
Count = 500000
Count = 166667
# find the largest good number in the divisors of given number n | function to return distinct prime factors ; to store distinct prime factors ; run a loop upto sqrt ( n ) ; place this prime factor in vector ; this condition is to handle the case when n is a prime number greater than 1 ; function that returns good number ; distinct prime factors ; to store answer ; product of all distinct prime factors is required answer ; 
def PrimeFactors(n):
    v = []
    x = n
    i = 2
    while (i * i <= n):
        if (x % i == 0):
            v .append(i)
            while (x % i == 0):
                x //= i
        i += 1
    if (x > 1):
        v .append(x)
    return v


def GoodNumber(n):
    v = PrimeFactors(n)
    ans = 1
    for i in range(len(v)):
        ans *= v[i]
    return ans


if __name__ == "__main__":
    n = 12
    print(GoodNumber(n))

# Expected output:
6
# find largest special prime which is less than or equal to a given number | function to check whether the number is a special prime or not ; while number is not equal to zero ; if the number is not prime return false . ; else remove the last digit by dividing the number by 10. ; if the number has become zero then the number is special prime , hence return true ; function to find the largest special prime which is less than or equal to a given number ; initially all numbers are considered primes . ; there is always an answer possible ; checking if the number is a special prime or not ; if yes print the number and break the loop . ; else decrement the number . ; 
def checkSpecialPrime(sieve, num):
    while (num):
        if (not sieve[num]):
            return False
        num //= 10
    return True


def findSpecialPrime(N):
    sieve = [True] * (N + 10)
    sieve[0] = sieve[1] = False
    for i in range(2, N + 1):
        if (sieve[i]):
            for j in range(i * i, N + 1, i):
                sieve[j] = False
    while (True):
        if (checkSpecialPrime(sieve, N)):
            print(N)
            break
        else:
            N -= 1


if __name__ == "__main__":
    findSpecialPrime(379)
    findSpecialPrime(100)

# Expected output:
379
79
# check if a number is a pythagorean prime or not | utility function to check if a number is prime or not ; corner cases ; this is checked so that we can skip middle five numbers in below loop ; 
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


n = 13
if (isPrime(n) and (n % 4 == 1)):
    print("YES")
else:
    print("NO")

# Expected output:
YES
# divide an isosceles triangle in two parts with ratio of areas as n : m | python 3 program , to find height h which divide isosceles triangle into ratio n : m ; function to return the height ; type cast the n , m into float ; calculate the height for cut ; 

from math import sqrt


def heightCalculate(H, n, m):
    N = n * 1.0
    M = m * 1.0
    h = H * sqrt(N / (N + M))
    return h


if __name__ == '__main__':
    H = 10
    n = 3
    m = 4
    print("{0:.6}".format(heightCalculate(H, n, m)))

# Expected output:
6.54654
# check n ^ 2 | check a number is prime or not ; run a loop upto square of given number ; check if n ^ 2 - m ^ 2 is prime ; 
def isprime(x):
    for i in range(2, math .sqrt(x)):
        if (x % i == 0):
            return False
    return True


def isNSqMinusnMSqPrime(m, n):
    if (n - m == 1 and isprime(m + n)):
        return True
    else:
        return False


m = 13
n = 16
if (isNSqMinusnMSqPrime(m, n)):
    print("YES")
else:
    print("NO")

# Expected output:
NO
# find ' n ' number of solutions with the 
def findsolution(n, x, y):
    if ((y - n + 1) * (y - n + 1) + n - 1 < x or y < n):
        print("No solution")
        return
    print(y - n + 1)
    while (n > 1):
        print(1)
        n -= 1


n = 5
x = 15
y = 15
findsolution(n, x, y)

# Expected output:
11
1
1
1
1
# number of different positions where a person can stand | function to find the position ; 
def findPosition(n, f, b):
    return n - max(f + 1, n - b) + 1


n, f, b = 5, 2, 3
print(findPosition(n, f, b))

# Expected output:
3
# program for n | function to find the nth odd number ; 
def nthOdd(n):
    return (2 * n - 1)


if __name__ == '__main__':
    n = 10
    print(nthOdd(n))

# Expected output:
19
# program for n | function to find the nth even number ; 
def nthEven(n):
    return (2 * n)


if __name__ == '__main__':
    n = 10
    print(nthEven(n))

# Expected output:
20
# program to find the nth harmonic number | function to find n - th harmonic number ; h1 = 1 ; loop to apply the forumula hn = h1 + h2 + h3 ... + hn - 1 + hn - 1 + 1 / n ; 
def nthHarmonic(N):
    harmonic = 1.00
    for i in range(2, N + 1):
        harmonic += 1 / i
    return harmonic


if __name__ == "__main__":
    N = 8
    print(round(nthHarmonic(N), 5))

# Expected output:
2.71786
# program to find nth term of series 0 , 7 , 18 , 33 , 51 , 75 , 102 , 133 , ... . . | calculate nth term of series ; 
def nthTerm(n):
    return 2 * pow(n, 2) + n - 3


N = 4
print(nthTerm(N))

# Expected output:
33
# program to find nth term of series 0 , 10 , 30 , 60 , 99 , 150 , 210 , 280. ... ... ... . | calculate nth term of series ; 
def nthTerm(n):
    return 5 * pow(n, 2) - 5 * n


N = 4
print(nthTerm(N))

# Expected output:
60
# program to find nth term of series 2 , 12 , 28 , 50 , 77 , 112 , 152 , 198 , ... . . | calculate nth term of series ; 
def nthTerm(n):
    return 3 * pow(n, 2) + n - 2


N = 4
print(nthTerm(N))

# Expected output:
50
# program to find nth term of series 4 , 14 , 28 , 46 , 68 , 94 , 124 , 158 , ... . . | calculate nth term of series ; 
def nthTerm(n):
    return 2 * pow(n, 2) + 4 * n - 2


N = 4
print(nthTerm(N))

# Expected output:
46
# program to find nth term of series 0 , 11 , 28 , 51 , 79 , 115 , 156 , 203 , ... . | calculate nth term of series ; 
def nthTerm(n):
    return 3 * pow(n, 2) + 2 * n - 5


N = 4
print(nthTerm(N))

# Expected output:
51
# program to find nth term of series 0 , 9 , 22 , 39 , 60 , 85 , 114 , 147 , ... . . | calculate nth term of series ; 
def nthTerm(n):
    return 2 * pow(n, 2) + 3 * n - 5


N = 4
print(nthTerm(N))

# Expected output:
39
# program to find nth term of series 3 , 12 , 29 , 54 , 86 , 128 , 177 , 234 , ... . . | calculate nth term of series ; 
def nthTerm(n):
    return 4 * pow(n, 2) - 3 * n + 2


N = 4
print(nthTerm(N))

# Expected output:
54
# find other two sides and angles of a right angle triangle | python 3 program to print all sides and angles of right angle triangle given one side ; function to find angle a angle in front of side a ; applied cosine rule ; convert into degrees ; function to find angle b angle in front of side b ; applied cosine rule ; convert into degrees and return ; function to print all angles of the right angled triangle ; for calculate angle a ; for calculate angle b ; function to find other two sides of the right angled triangle ; if n is odd ; case of n = 1 handled separately ; case of n = 2 handled separately ; print angles of the triangle ; 

import math
PI = 3.1415926535


def findAnglesA(a, b, c):
    A = math .acos((b * b + c * c - a * a) / (2 * b * c))
    return A * 180 / PI


def findAnglesB(a, b, c):
    B = math .acos((a * a + c * c - b * b) / (2 * a * c))
    return B * 180 / PI


def printAngles(a, b, c):
    x = a
    y = b
    z = c
    A = findAnglesA(x, y, z)
    B = findAnglesB(x, y, z)
    print("Angles are A = ", A, ", B = ", B, ", C = ", "90 ")


def printOtherSides(n):
    if (n & 1):
        if (n == 1):
            print("-1")
        else:
            b = (n * n - 1) // 2
            c = (n * n + 1) // 2
            print("Side b = ", b, " Side c = ", c)
    else:
        if (n == 2):
            print("-1")
        else:
            b = n * n // 4 - 1
            c = n * n // 4 + 1
            print("Side b = ", b, ", Side c = ", c)
    printAngles(n, b, c)


if __name__ == "__main__":
    a = 12
    printOtherSides(a)

# Expected output:
Side b =  35 , Side c =  37
Angles are A =  18.92464441659214 , B =  71.07535558598025 , C =  90
# Sum of the first N terms of the series 2 , 6 , 12 , 20 , 30. ... | 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 + n * (n + 1) * (2 * n + 1) // 6)


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

# Expected output:
Sum =  20
# program to find the nth term of the series 0 , 5 , 14 , 27 , 44 , ... ... . . | calculate nth term of series ; 
def nthTerm(n):
    return 2 * pow(n, 2) - n - 1


if __name__ == "__main__":
    N = 4
    print(nthTerm(N))

# Expected output:
27
# program to find the nth term of the series 0 , 5 , 18 , 39 , 67 , 105 , 150 , 203 , ... | calculate nth term of series ; 
def nthTerm(n):
    return 4 * pow(n, 2) - 7 * n + 3


N = 4
print(nthTerm(N))

# Expected output:
39
# check whether a given number is power | python3 program to find whether a number is power - isolated or not ; for 2 as prime factor ; for odd prime factor ; calculate product of powers and prime factors ; check result for power - isolation ; 
def checkIfPowerIsolated(num):
    input1 = num
    count = 0
    factor = [0] * (num + 1)
    if (num % 2 == 0):
        while (num % 2 == 0):
            count += 1
            num //= 2
        factor[2] = count
    i = 3
    while (i * i <= num):
        count = 0
        while (num % i == 0):
            count += 1
            num //= i
        if (count > 0):
            factor[i] = count
        i += 2
    if (num > 1):
        factor[num] = 1
    product = 1
    for i in range(0, len(factor)):
        if (factor[i] > 0):
            product = product * factor[i] * i
    if (product == input1):
        print("Power-isolated Integer")
    else:
        print("Not a Power-isolated Integer")


checkIfPowerIsolated(12)
checkIfPowerIsolated(18)
checkIfPowerIsolated(35)

# Expected output:
Power-isolated Integer
Not a Power-isolated Integer
Power-isolated Integer
# program to find the nth term of the series 3 , 7 , 13 , 21 , 31. ... . | function to calculate sum ; return nth term ; 
def getNthTerm(N):
    return (pow(N, 2) + N + 1)


if __name__ == '__main__':
    N = 11
    print(getNthTerm(N))

# Expected output:
133
# sum of the numbers upto n that are divisible by 2 or 5 | function to find the sum ; sum2 is sum of numbers divisible by 2 ; sum5 is sum of number divisible by 5 ; sum10 of numbers divisible by 2 and 5 ; 
def findSum(n):
    sum2 = ((n // 2) * (4 + (n // 2 - 1) * 2)) // 2
    sum5 = ((n // 5) * (10 + (n // 5 - 1) * 5)) // 2
    sum10 = ((n // 10) * (20 + (n // 10 - 1) * 10)) // 2
    return sum2 + sum5 - sum10


if __name__ == '__main__':
    n = 5
    print(int(findSum(n)))

# Expected output:
11
# find four factors of n with maximum product and sum equal to n | set 3 | python3 implementation of above approach ; function to find primes ; corner cases ; this is checked so that we can skip middle five numbers in below loop ; function to find factors ; run a loop upto square root of that number ; if the n is perfect square ; otherwise push it 's two divisors ; sort the divisors ; function to find max product ; to store factors of 'n ; find factors ; if it is divisible by 4. ; if it is prime ; otherwise answer will be possible ; include last third factor ; nested loop to find other two factors ; 

from math import sqrt, ceil, floor


def isPrime(n):
    if (n <= 1):
        return False
    if (n <= 3):
        return True
    if (n % 2 == 0 or n % 3 == 0):
        return False

    for i in range(5, ceil(sqrt(n)), 6):
        if (n % i == 0 or n % (i + 2) == 0):
            return False

    return True


def factors(N, v):
    for i in range(2, N):
        for j in range(1, ceil(sqrt(i)) + 1):
            if (i % j == 0):
                if (i // j == j):
                    v[i].append(j)
                else:
                    v[i].append(j)
                    v[i].append(i // j)

        v = sorted(v)


def product(n):
    v = [[]] * (n + 100)
    factors(n + 100, v)
    if (n % 4 == 0):
        x = n // 4
        x *= x
        return x * x

    else:
        if (isPrime[n]):
            return -1
        else:
            ans = -1
            if (len(v[n]) > 2):
                fac = v[n][len(v[n]) - 3]
                for i in range(len(v[n] - 1), -1, -1):
                    for j in range(len(v[n] - 1), -1, -1):
                        if ((fac * 2) + (v[n][j] + v[n][i]) == n):
                            ans = max(ans, fac * fac * v[n][j] * v[n][i])

                return ans


n = 24
print(product(n))

# Expected output:
1296
# ratio of mth and nth terms of an a . p . with given ratio of sums | function to calculate ratio of mth and nth term ; ratio will be tm / tn = ( 2 * m - 1 ) / ( 2 * n - 1 ) ; 
def CalculateRatio(m, n):
    return (2 * m - 1) / (2 * n - 1)


if __name__ == '__main__':
    m = 6
    n = 2
    print(float(CalculateRatio(m, n)))

# Expected output:
3.6666666666666665
# find the sum of n terms of the series 1 , 8 , 27 , 64 ... . | function to calculate the sum ; return total sum ; 
def calculateSum(n):
    return (n * (n + 1) / 2)**2


if __name__ == '__main__':
    n = 4
    print(calculateSum(n))

# Expected output:
100.0
# sum of digits in a ^ n till a single digit | this function finds single digit sum of n . ; returns single digit sum of a ^ n . we use modular exponentiation technique . ; 
def digSum(n):
    if n == 0:
        return 0
    elif n % 9 == 0:
        return 9
    else:
        return n % 9


def powerDigitSum(a, n):
    res = 1
    while (n):
        if n % 2 == 1:
            res = res * digSum(a)
            res = digSum(res)
        a = digSum(digSum(a) * digSum(a))
        n //= 2
    return res


if __name__ == "__main__":
    a, n = 9, 4
    print(powerDigitSum(a, n))

# Expected output:
9
# program to find total number of edges in a complete graph | function to find the total number of edges in a complete graph with n vertices ; 
def totEdge(n):
    result = (n * (n - 1)) // 2
    return result


if __name__ == "__main__":
    n = 6
    print(totEdge(n))

# Expected output:
15
# find minimum number of log value needed to calculate log upto n | python3 program to find number of log values needed to calculate all the log values from 1 to n ; in this list prime [ i ] will store true if prime [ i ] is prime , else store false ; using sieve of eratosthenes to find all prime upto n ; function to find number of log values needed to calculate all the log values from 1 to n ; calculate primes upto n ; 

MAX = 1000005
prime = [True for i in range(MAX)]


def sieve(N):
    prime[0], prime[1] = False, False
    for i in range(2, N + 1):
        if (prime[i]):
            for j in range(2, N + 1):
                if (i * j > N):
                    break
                prime[i * j] = False


def countLogNeeded(N):
    count = 0
    sieve(N)
    for i in range(1, N + 1):
        if (prime[i]):
            count = count + 1
    return count


if __name__ == '__main__':
    N = 6
    print(countLogNeeded(N))

# Expected output:
3
# program to find the count of coins of each type from the given ratio | function to calculate coin . ; converting each of them in rupees . as we are given totalrupees = 1800 ; 
def coin(totalRupees, X, Y, Z):
    one = X * 1
    fifty = ((Y * 1) / 2.0)
    twentyfive = ((Z * 1) / 4.0)
    total = one + fifty + twentyfive
    result = ((totalRupees) / total)
    return int(result)


if __name__ == '__main__':
    totalRupees = 1800
    X, Y, Z = 1, 2, 4
    Rupees = coin(totalRupees, X, Y, Z)
    print("1 rupess coins = ", Rupees * 1)
    print("50 paisa coins = ", Rupees * 2)
    print("25 paisa coins = ", Rupees * 4)

# Expected output:
1 rupess coins =  600
50 paisa coins =  1200
25 paisa coins =  2400
# find the sum of series 0. x + 0. xx + 0. xxx + ... upto k terms | function which return the sum of series ; 
def sumOfSeries(x, k):
    return (float(x) / 81) * (9 * k - 1 + 10 ** ((-1) * k))


if __name__ == '__main__':
    x = 9
    k = 20
    print(sumOfSeries(x, k))

# Expected output:
19.88888888888889
# find four factors of n with maximum product and sum equal to n | set | python3 program to find four factors of n with maximum product and sum equal to n ; function to find factors and to prthose four factors ; push all the factors in the container ; number of factors ; initial maximum ; hash - array to mark the pairs ; form all the pair sums ; if the pair sum is less than n ; push in another container ; mark the sum with the elements formed ; mark in the map that v [ i ] + v [ j ] is present ; new size of all the pair sums ; iterate for all pair sum ; the required part ; if the required part is also present in pair sum ; find the elements with which the first pair is formed ; find the elements with which the second pair is formed ; check for previous maximum ; 

from math import sqrt, ceil, floor


def findfactors(n):
    mpp = dict()
    v = []
    v1 = []
    for i in range(1, ceil(sqrt(n)) + 1):
        if (n % i == 0):
            v .append(i)
            if (i != (n // i) and i != 1):
                v .append(n // i)
    s = len(v)
    maxi = -1
    mp1 = [0] * (n + 5)
    for i in range(s):
        for j in range(i, s):
            if (v[i] + v[j] < n):
                v1 .append(v[i] + v[j])
                mp1[v[i] + v[j]] = [v[i], v[j]]
                mpp[v[i] + v[j]] = 1
    s = len(v1)
    for i in range(s):
        el = n - (v1[i])
        if (el in mpp):
            a = mp1[v1[i]][0]
            b = mp1[v1[i]][1]
            c = mp1[n - v1[i]][0]
            d = mp1[n - v1[i]][1]
            maxi = max(a * b * c * d, maxi)
    if (maxi == -1):
        print("Not Possible")
    else:
        print("The maximum product is ", maxi)


n = 50
findfactors(n)

# Expected output:
The maximum product is  12500
# maximize the product of four factors of a number | for calculation of a ^ b ; function to check ; every odd and number less than 3. ; every number divisible by 4. ; every number divisible by 6. ; every number divisible by 10. ; for every even number which is not divisible by above values . ; 
def modExp(a, b):
    result = 1
    while (b > 0):
        if (int(b) & 1):
            result = result * a
        a = a * a
        b /= 2
    return result


def check(num):
    if (num & 1 or num < 3):
        return -1
    elif (num % 4 == 0):
        return modExp(num / 4, 4)
    elif (num % 6 == 0):
        return modExp(num / 3, 2) * modExp(num / 6, 2)
    elif (num % 10 == 0):
        return modExp(num / 5, 2) * (num / 10) * (num / 2)
    else:
        return -1


if __name__ == '__main__':
    num = 10
    print(int(check(num)))

# Expected output:
20
# check if any large number is divisible by 17 or not | function to check if the number is divisible by 17 or not ; extracting the last digit ; truncating the number ; subtracting the five times the last digit from the remaining number ; return n is divisible by 17 ; 
def isDivisible(n):
    while (n // 100):
        d = n % 10
        n //= 10
        n -= d * 5
    return (n % 17 == 0)


if __name__ == "__main__":
    n = 19877658
    if isDivisible(n):
        print("Yes")
    else:
        print("No")

# Expected output:
Yes
# minimum number of elements to be removed to make xor maximum | python 3 to find minimum number of elements to remove to get maximum xor value ; first n in the below condition is for the case where n is 0 ; function to find minimum number of elements to be removed . ; 
def nextPowerOf2(n):
    count = 0
    if (n and not (n and (n - 1))):
        return n
    while n != 0:
        n >>= 1
        count += 1
    return 1 << count


def removeElement(n):
    if n == 1 or n == 2:
        return 0
    a = nextPowerOf2(n)
    if n == a or n == a - 1:
        return 1
    elif n == a - 2:
        return 0
    elif n % 2 == 0:
        return 1
    else:
        return 2


if __name__ == "__main__":
    n = 5
    print(removeElement(n))

# Expected output:
2
# program to find length of bridge using speed and length of train | function to calculate the length of bridge . ; 
def bridge_length(trainLength, Speed, Time):
    return ((Time * Speed) - trainLength)


if __name__ == "__main__":
    trainLength = 120
    Speed = 30
    Time = 18
    print(
        "Length of bridge = ",
        bridge_length(
            trainLength,
            Speed,
            Time),
        "meters")

# Expected output:
Length of bridge =  420 meters