giulio98/xlcost-single-prompt huggingface dataset:
# Expressing a number as sum of consecutive | Set 2 ( Using odd factors ) | returns the number of odd factors ; If i is an odd factor and n is a perfect square ; If n is not perfect square ; N as sum of consecutive numbers
def countOddFactors(n):
    odd_factors = 0
    i = 1
    while ((1 * i * i) <= n):
        if (n % i == 0):
            if (1 * i * i == n):
                if (i & 1):
                    odd_factors = odd_factors + 1
            else:
                if ((i & 1)):
                    odd_factors = odd_factors + 1
                factor = int(n / i)
                if (factor & 1):
                    odd_factors = odd_factors + 1
        i = i + 1
    return odd_factors - 1


N = 15
print(countOddFactors(N))
N = 10
print(countOddFactors(N))

# Expected output:
3
1
# making zero array by decrementing pairs of adjacent | python3 program to find if it is possible to make all array elements 0 by decrement operations . ; used for storing the sum of even and odd position element in array . ; if position is odd , store sum value of odd position in odd ; if position is even , store sum value of even position in even ; 
def isPossibleToZero(a, n):
    even = 0
    odd = 0
    for i in range(n):
        if (i & 1):
            odd += a[i]
        else:
            even += a[i]
    return (odd == even)


arr = [0, 1, 1, 0]
n = len(arr)
if (isPossibleToZero(arr, n)):
    print("YES")
else:
    print("NO")

# Expected output:
YES
# program for sum of cos ( x ) series | python3 program to find the sum of cos ( x ) series ; here x is in degree . we have to convert it to radian for using it with series formula , as in series expansion angle is in radian ; 

PI = 3.142


def cosXSertiesSum(x, n):
    x = x * (PI / 180.0)
    res = 1
    sign = 1
    fact = 1
    pow = 1
    for i in range(1, 5):
        sign = sign * (-1)
        fact = fact * (2 * i - 1) * (2 * i)
        pow = pow * x * x
        res = res + sign * pow / fact
    return res


x = 50
n = 5
print(round(cosXSertiesSum(x, 5), 6))

# Expected output:
0.642701
# sum of digits written in different bases from 2 to n | def to calculate sum of digit for a given base ; sum of digits ; calculating the number ( n ) by taking mod with the base and adding remainder to the result and parallelly reducing the num value . ; returning the result ; def calling for multiple bases ; 
def solve(n, base):
    result = 0
    while (n > 0):
        remainder = n % base
        result = result + remainder
        n = int(n / base)
    return result


def printSumsOfDigits(n):
    for base in range(2, n):
        print(solve(n, base), end=" ")


n = 8
printSumsOfDigits(n)

# Expected output:
1 4 2 4 3 2
# possible two sets from first n natural numbers difference of sums as d | function returns true if it is possible to split into two sets otherwise returns false ; 
def check(N, D):
    temp = N * (N + 1) // 2 + D
    return (bool(temp % 2 == 0))


N = 5
M = 7
if check(N, M):
    print("yes")
else:
    print("no")

# Expected output:
yes
# minimum digits to remove to make a number perfect square | c ++ program to find required minimum digits need to remove to make a number perfect square ; function to check minimum number of digits should be removed to make this number a perfect square ; size of the string ; our final answer ; to store string which is perfect square . ; we make all possible subsequences ; to check jth bit is set or not . ; we do not consider a number with leading zeros ; convert our temporary string into integer ; checking temp is perfect square or not . ; taking maximum sized string ; print perfectsquare ; 

import math


def perfectSquare(s):
    n = len(s)
    ans = -1
    num = ""
    for i in range(1, (1 << n)):
        str = ""
        for j in range(0, n):
            if ((i >> j) & 1):
                str = str + s[j]
        if (str[0] != '0'):
            temp = 0
            for j in range(0, len(str)):
                temp = (temp * 10 + (ord(str[j]) - ord('0')))
            k = int(math .sqrt(temp))
            if (k * k == temp):
                if (ans < len(str)):
                    ans = len(str)
                    num = str
    if (ans == -1):
        return ans
    else:
        print("{} ".format(num), end="")
        return n - ans


print(perfectSquare("8314"))
print(perfectSquare("753"))

# Expected output:
81 2
-1
# lagrange 's four square theorem | prints all the possible combinations 4 numbers whose sum of squares is equal to the given no . ; loops checking the sum of squares ; if sum of four squares equals the given no . ; printing the numbers ; 
def printFourSquares(a):
    i = 0
    while (i * i <= a):
        j = i
        while (j * j <= a):
            k = j
            while (k * k <= a):
                l = k
                while (l * l <= a):
                    if (i * i + j * j + k * k + l * l == a):
                        print("{} = {}*{} + {}*{} +".format(a, i, i, j, j), end=" ")
                        print("{}*{} + {}*{}".format(k, k, l, l), end="")
                    l = l + 1
                k = k + 1
            j = j + 1
        i = i + 1


a = 74
printFourSquares(a)

# Expected output:
74 = 0*0 + 0*0 + 5*5 + 7*774 = 0*0 + 1*1 + 3*3 + 8*874 = 0*0 + 3*3 + 4*4 + 7*774 = 1*1 + 1*1 + 6*6 + 6*674 = 2*2 + 3*3 + 5*5 + 6*6
# hardy | python3 program to count all prime factors ; a function to count prime factors of a given number n ; n must be odd at this point . so we can skip one element ( note i = i + 2 ) ; this condition is to handle the case when n is a prime number greater than 2 ; 

import math


def exactPrimeFactorCount(n):
    count = 0
    if (n % 2 == 0):
        count = count + 1
        while (n % 2 == 0):
            n = int(n / 2)
    i = 3
    while (i <= int(math .sqrt(n))):
        if (n % i == 0):
            count = count + 1
            while (n % i == 0):
                n = int(n / i)
        i = i + 2
    if (n > 2):
        count = count + 1
    return count


n = 51242183
print("The number of distinct prime factors is/are {}".format(exactPrimeFactorCount(n), end=""))
print("The value of log(log(n)) is {0:.4f}".format(math .log(math .log(n))))

# Expected output:
The number of distinct prime factors is/are 3
The value of log(log(n)) is 2.8765
# number of digits in a ^ b | python program to calculate no . of digits in a ^ b ; function to calculate number of digits in a ^ b ; 

import math


def no_of_digit(a, b):
    return ((int)(b * math .log10(a)) + 1)


a = 2
b = 100
print("no of digits = ", no_of_digit(a, b))

# Expected output:
no of digits =  31
# check whether a number is emirpimes or not | checking whether a number is semi - prime or not ; increment count of prime numbers ; if number is still greater than 1 , after exiting the add it to the count variable as it indicates the number is a prime number ; return '1' if count is equal to '2' else return '0 ; checking whether a number is emirpimes or not ; number itself is not semiprime . ; finding reverse of n . ; the definition of emirpimes excludes palindromes , hence we do not check further , if the number entered is a palindrome ; checking whether the reverse of the semi prime number entered is also a semi prime number or not ; 
def checkSemiprime(num):
    cnt = 0
    i = 2
    while (cnt < 2 and (i * i) <= num):
        while (num % i == 0):
            num /= i
            cnt += 1
        i += 1
    if (num > 1):
        cnt += 1
    return cnt == 2


def isEmirpimes(n):
    if (checkSemiprime(n) == False):
        return False
    r = 0
    t = n
    while (t != 0):
        r = r * 10 + t % 10
        t = t / n
    if (r == n):
        return false
    return (checkSemiprime(r))


n = 15
if (isEmirpimes(n)):
    print("No")
else:
    print("Yes")

# Expected output:
Yes
# connell sequence | function to generate a fixed number of even or odd terms . the size of r decides whether numbers to be generated even or odd . ; generating the first ' n ' terms of connell sequence ; a dummy 0 is inserted at the beginning for consistency ; calling function gen ( ) to generate ' k ' number of terms ; checking if ' n ' terms are already generated ; removing the previously inserted dummy 0 ; 
def gen(n, r):
    a = r[-1]
    a += 1
    for i in range(1, n + 1):
        r .append(a)
        a += 2
    return r


def conell(n):
    res = []
    k = 1
    res .append(0)
    while 1:
        res = gen(k, res)
        k += 1
        j = len(res) - 1
        while j != n and j + k > n:
            k -= 1
        if j >= n:
            break
    res .remove(res[0])
    return res


if __name__ == "__main__":
    n = 10
    print("The first %d terms are" % n)
    res = conell(n)
    for i in range(len(res)):
        print(res[i], end=" ")
    print()

# Expected output:
The first 10 terms are
1 2 4 5 7 9 10 12 14 16
# generate a list of n consecutive composite numbers ( an interesting method ) | function to find factorial of given number ; prints n consecutive numbers . ; 
def factorial(n):
    res = 1
    for i in range(2, n + 1):
        res *= i
    return res


def printNComposite(n):
    fact = factorial(n + 1)
    for i in range(2, n + 2):
        print(fact + i, end=" ")


n = 4
printNComposite(n)

# Expected output:
122 123 124 125
# frugal number | finding primes upto entered number ; finding primes by sieve of eratosthenes method ; if prime [ i ] is not changed , then it is prime ; update all multiples of p ; forming array of the prime numbers found ; returns number of digits in n ; checking whether a number is frugal or not ; finding number of digits in prime factorization of the number ; exponent for current factor ; counting number of times this prime factor divides ( finding exponent ) ; finding number of digits in the exponent avoiding exponents of value 1 ; checking condition for frugal number ; 
def primes(n):
    prime = [True] * (n + 1)
    i = 2
    while (i * i <= n):
        if (prime[i]):
            j = i * 2
            while (j <= n):
                prime[j] = False
                j += i
        i += 1
    arr = []
    for i in range(2, n):
        if (prime[i]):
            arr .append(i)
    return arr


def countDigits(n):
    temp = n
    c = 0
    while (temp != 0):
        temp = int(temp / 10)
        c += 1
    return c


def frugal(n):
    r = primes(n)
    t = n
    s = 0
    for i in range(len(r)):
        if (t % r[i] == 0):
            k = 0
            while (t % r[i] == 0):
                t = int(t / r[i])
                k += 1
            if (k == 1):
                s = s + countDigits(r[i])
            elif (k != 1):
                s = (s + countDigits(r[i]) + countDigits(k))
    return (countDigits(n) > s and s != 0)


n = 343
if (frugal(n)):
    print("A Frugal number")
else:
    print("Not a frugal number")

# Expected output:
A Frugal number
# n | program to find n - th number which is both square and cube . ; 
def nthSquareCube(n):
    return n * n * n * n * n * n


n = 5
print(nthSquareCube(n))

# Expected output:
15625
# squared triangular number ( sum of cubes ) | function to find if the given number is sum of the cubes of first n natural numbers ; start adding cubes of the numbers from 1 ; if sum becomes equal to s return n ; 
def findS(s):
    _sum = 0
    n = 1
    while (_sum < s):
        _sum += n * n * n
        n += 1
    n -= 1
    if _sum == s:
        return n
    return -1


s = 9
n = findS(s)
if n == -1:
    print("-1")
else:
    print(n)

# Expected output:
2
# number with even sum of digits | function to find kth good number . ; find the last digit of n . ; if last digit is between 0 to 4 then return 2 * n . ; if last digit is between 5 to 9 then return 2 * n + 1. ; 
def findKthGoodNo(n):
    lastDig = n % 10
    if (lastDig >= 0 and lastDig <= 4):
        return n << 1
    else:
        return (n << 1) + 1


n = 10
print(findKthGoodNo(n))

# Expected output:
20
# nicomachu 's theorem | python3 program to verify nicomachu 's theorem ; compute sum of cubes ; check if sum is equal to given formula . ; 
def NicomachuTheorum_sum(n):
    sum = 0
    for k in range(1, n + 1):
        sum += k * k * k
    triNo = n * (n + 1) / 2
    if (sum == triNo * triNo):
        print("Yes")
    else:
        print("No")


n = 5
NicomachuTheorum_sum(n)

# Expected output:
Yes
# largest even digit number not greater than n | function to check if all digits are even of a given number ; iterate for all digits ; if digit is odd ; all digits are even ; function to return the largest number with all digits even ; iterate till we find a number with all digits even ; 
def checkDigits(n):
    while (n > 0):
        if ((n % 10) % 2):
            return False
        n = int(n / 10)
    return True


def largestNumber(n):
    for i in range(n, -1, -1):
        if (checkDigits(i)):
            return i


N = 23
print(largestNumber(N))

# Expected output:
22
# largest even digit number not greater than n | python3 program to print the largest integer not greater than n with all even digits ; function to return the largest number with all digits even ; convert the number to a string for easy operations ; find first odd digit ; if no digit , then n is the answer ; till first odd digit , add all even numbers ; decrease 1 from the odd digit ; add 0 in the rest of the digits ; 

import math as mt


def largestNumber(n):
    s = ""
    duplicate = n
    while (n > 0):
        s = chr(n % 10 + 48) + s
        n = n // 10
    index = -1
    for i in range(len(s)):
        if ((ord(s[i]) - ord('0')) % 2 & 1):
            index = i
            break
    if (index == -1):
        return duplicate
    num = 0
    for i in range(index):
        num = num * 10 + (ord(s[i]) - ord('0'))
    num = num * 10 + (ord(s[index]) - ord('0') - 1)
    for i in range(index + 1, len(s)):
        num = num * 10 + 8
    return num


N = 24578
print(largestNumber(N))

# Expected output:
24488
# number of digits in 2 raised to power n | python3 program to find number of digits in 2 ^ n ; function to find number of digits in 2 ^ n ; 

import math


def countDigits(n):
    return int(n * math .log10(2) + 1)


n = 5
print(countDigits(n))

# Expected output:
2
# smallest even digits number not less than n | function to check if all digits are even of a given number ; iterate for all digits ; if digit is odd ; all digits are even ; function to return the smallest number with all digits even ; iterate till we find a number with all digits even ; 
def check_digits(n):
    while (n):
        if ((n % 10) % 2):
            return 0
        n = int(n / 10)
    return 1


def smallest_number(n):
    for i in range(n, 2401):
        if (check_digits(i) == 1):
            return (i)


N = 2397
print(str(smallest_number(N)))

# Expected output:
2400
# smallest triangular number larger than p | python 3 code to find the bucket to choose for picking flowers out of it ; 

import math


def findBucketNo(p):
    return math .ceil((math .sqrt(8 * p + 1) - 1) / 2)


p = 10
print(findBucketNo(p))

# Expected output:
4
# lcm of factorial and its neighbors | function to calculate the factorial ; returning the factorial of the largest number in the given three consecutive numbers ; 
def factorial(n):
    if (n == 0):
        return 1
    return n * factorial(n - 1)


def LCMOfNeighbourFact(n):
    return factorial(n + 1)


N = 5
print(LCMOfNeighbourFact(N))

# Expected output:
720
# check if the given two numbers are friendly pair or not | check if the given two number are friendly pair or not . ; returns sum of all factors of n . ; traversing through all prime factors . ; the below statement makes it better than above method as we reduce value of n . ; this condition is to handle the case when n is a prime number greater than 2. ; function to return gcd of a and b ; function to check if the given two number are friendly pair or not . ; finding the sum of factors of n and m ; finding gcd of n and sum of its factors . ; finding gcd of m and sum of its factors . ; checking is numerator and denominator of abundancy index of both number are equal or not . ; 

import math


def sumofFactors(n):
    res = 1
    for i in range(2, int(math .sqrt(n)) + 1):
        count = 0
        curr_sum = 1
        curr_term = 1
        while (n % i == 0):
            count += 1
            n = n // i
            curr_term *= i
            curr_sum += curr_term
        res *= curr_sum
    if (n >= 2):
        res *= (1 + n)
    return res


def gcd(a, b):
    if (a == 0):
        return b
    return gcd(b % a, a)


def checkFriendly(n, m):
    sumFactors_n = sumofFactors(n)
    sumFactors_m = sumofFactors(m)
    gcd_n = gcd(n, sumFactors_n)
    gcd_m = gcd(m, sumFactors_m)
    if (n // gcd_n == m // gcd_m and sumFactors_n //
            gcd_n == sumFactors_m // gcd_m):
        return True
    else:
        return False


n = 6
m = 28
if (checkFriendly(n, m)):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# find n | python3 program to find n - th fortunate number ; corner cases ; this is checked so that we can skip middle five numbers in below loop ; function to find primorial of order n ( product of first n prime numbers ) . ; function to find next prime number greater than n ; note that difference ( or m ) should be greater than 1. ; loop continuously until isprime returns true for a number above n ; ignoring the prime number that is 1 greater than n ; returns n - th fortunate number ; 
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 += 6
    return True


def primorial(n):
    p = 2
    n -= 1
    i = 3
    while (n != 0):
        if (isPrime(i)):
            p = p * i
            n -= 1
        i += 1
    return p


def findNextPrime(n):
    nextPrime = n + 2
    while (True):
        if (isPrime(nextPrime)):
            break
        nextPrime += 1
    return nextPrime


def fortunateNumber(n):
    p = primorial(n)
    return findNextPrime(p) - p


n = 5
print(fortunateNumber(n))

# Expected output:
23
# probability for three randomly chosen numbers to be in ap | function to calculate probability ; 
def procal(n):
    return (3.0 * n) / (4.0 * (n * n) - 1)


a = [1, 2, 3, 4, 5]
n = len(a)
print(round(procal(n), 6))

# Expected output:
0.151515
# fermat 's last theorem | python3 program to verify fermat 's last theorem for a given range and n. ; check if there exists a triplet such that a ^ n + b ^ n = c ^ n ; 
def testSomeNumbers(limit, n):
    if (n < 3):
        return
    for a in range(1, limit + 1):
        for b in range(a, limit + 1):
            pow_sum = pow(a, n) + pow(b, n)
            c = pow(pow_sum, 1.0 / n)
            c_pow = pow(int(c), n)
            if (c_pow == pow_sum):
                print("Count example found")
                return
    print("No counter example within given range and data")


testSomeNumbers(10, 3)

# Expected output:
No counter example within given range and data
# product of given n fractions in reduced form | function to return gcd of a and b ; print the product of n fraction in reduced form . ; finding the product of all n numerators and denominators . ; finding gcd of new numerator and denominator ; converting into reduced form . ; 
def gcd(a, b):
    if (a == 0):
        return b
    return gcd(b % a, a)


def productReduce(n, num, den):
    new_num = 1
    new_den = 1
    for i in range(n):
        new_num = new_num * num[i]
        new_den = new_den * den[i]
    GCD = gcd(new_num, new_den)
    new_num = new_num / GCD
    new_den = new_den / GCD
    print(int(new_num), "/", int(new_den))


n = 3
num = [1, 2, 5]
den = [2, 1, 6]
productReduce(n, num, den)

# Expected output:
5 / 6
# find value of ( n ^ 1 + n ^ 2 + n ^ 3 + n ^ 4 ) mod 5 for given n | function for f ( n ) mod 5 ; if n % 5 == 1 return 4 ; else return 0 ; 
def fnMod(n):
    if (n % 5 == 1):
        return 4
    else:
        return 0


n = 10
print(fnMod(n))
n = 11
print(fnMod(n))

# Expected output:
0
4
# recursive sum of digits of a number formed by repeated appends | return single digit sum of a number ; returns recursive sum of digits of a number formed by repeating a number x number of times until sum become single digit . ; 
def digSum(n):
    if n == 0:
        return 0
    return (n % 9 == 0) and 9 or (n % 9)


def repeatedNumberSum(n, x):
    sum = x * digSum(n)
    return digSum(sum)


n = 24
x = 3
print(repeatedNumberSum(n, x))

# Expected output:
9
# sum of n digit numbers divisible by a given number | returns sum of n digit numbers divisible by 'number ; compute the first and last term ; sum of number which having n digit and divisible by number ; 
def totalSumDivisibleByNum(n, number):
    firstnum = pow(10, n - 1)
    lastnum = pow(10, n)
    sum = 0
    for i in range(firstnum, lastnum):
        if (i % number == 0):
            sum += i
    return sum


n = 3
num = 7
print(totalSumDivisibleByNum(n, num))

# Expected output:
70336
# count n digit numbers divisible by given number | simple python 3 program to count n digit divisible numbers ; returns count of n digit numbers divisible by number ; compute the first and last term ; count total number of which having n digit and divisible by number ; 

import math


def numberofterm(n, number):
    firstnum = math .pow(10, n - 1)
    lastnum = math .pow(10, n)
    count = 0
    for i in range(int(firstnum), int(lastnum)):
        if (i % number == 0):
            count += 1
    return count


n = 3
num = 7
print(numberofterm(n, num))

# Expected output:
128
# n | python3 program to find n - th term in george cantor set of rational numbers ; let i = numerator ; let j = denominator ; to keep the check of no . of terms ; loop till k is not equal to n ; check if k is already equal to n then the first term is the required rational number ; loop for traversing from right to left downwards diagonally ; loop for traversing from left to right upwards diagonally ; 
def georgeCantor(n):
    i = 1
    j = 1
    k = 1
    while k < n:
        j += 1
        k += 1
        if k == n:
            break
        while j > 1 and k < n:
            i += 1
            j -= 1
            k += 1
        if k == n:
            break
        i += 1
        k += 1
        if k == n:
            break
        while i > 1 and k < n:
            i -= 1
            j += 1
            k += 1
    print("N-th term : %d/%d" % (i, j))


n = 15
georgeCantor(n)

# Expected output:
N-th term : 1/5
# number is divisible by 29 or not | returns true if n is divisible by 29 else returns false . ; add the lastdigit * 3 to renaming number until number comes only 2 digit ; return true if number is divisible by 29 another ; 
def isDivisible(n):
    while (int(n / 100)):
        last_digit = int(n % 10)
        n = int(n / 10)
        n += last_digit * 3
    return (n % 29 == 0)


n = 348
if (isDivisible(n) != 0):
    print("Yes")
else:
    print("No")

# Expected output:
Yes