School of Computer Science Engineering and Technology
Course-B.Tech Type- Core
Course Code- CSET304 Course Name- Competitive Programming
Year- 2025 Semester- ODD
Date- 28/07/2025 Batch- 2024 - 2025
Q1.
Statement An Armstrong number is the one whose sum of the nth power of its digits is
equal to the number itself. Your task is to print all the Armstrong numbers in
the range [lower, upper]. If no Armstrong Number is found between the
given range, print -1.
Input Two integer values each in a new line representing lower and upper.
Format
Output Space separated armstrong numbers in range or -1.
Format
Constraint 1 < numbers < 10 ^ 5
Sample 100
Input 1 999
Sample 153 370 371 407
Output 1
Test Case 1
Input 1 100
Test Case 123456789
Output 1
Test Case 500
Input 2 1000
Test Case -1
Output 2
Test Case 1000
Input 3 10000
Test Case 1634 8208 9474
Output 3
Code def isArmstrong(num: int) -> bool:
order = len(str(num))
temp, res = num, 0
while temp > 0:
digit = temp % 10
res += digit ** order
temp //= 10
return res == num
def allArmstrong(lower: int, upper: int) -> list[int]:
res = []
for i in range(lower, upper + 1):
if isArmstrong(i) == True:
res.append(i)
if len(res) == 0:
res.append(-1)
return res
lower = int(input())
upper = int(input())
print(*allArmstrong(lower, upper))
Q2.
Statement Given a positive number X. Check whether number X is a perfect number or
not. A perfect number is a number which is equal to the sum of its proper
positive divisors.
Input Single line input, an integer value.
Format
Output Print Perfect Number (when a number is a perfect number) or Not Prefect
Format Number (when a number is not a perfect number).
Constraint 2 <= X <= 10^4
Sample 12
Input 1
Sample Not Perfect Number
Output 1
Explanation Proper divisors of 12 is 1, 2, 3, 4, 6 and the sum of divisors is 16 not equal
to 12, therefore Not Perfect Number.
Sample 28
Input 2
Sample Perfect Number
Output 2
Explanation Proper divisors of 28 are 1, 2, 4, 7, 14, and the sum of divisors is 28, which
is equal to number 28, therefore the output is Perfect Number.
Test Case 6
Input 1
Test Case Perfect Number
Output 2
Test Case 28
Input 2
Test Case Perfect Number
Output 2
Test Case 15
Input 3
Test Case Not Perfect Number
Output 3
Test Case 496
Input 4
Test Case Perfect Number
Output 4
Test Case 8128
Input 5
Test Case Perfect Number
Output 5
Test Case 2000
Input 5
Test Case Not Perfect Number
Output 5
Code def checkPerfect(num: int) -> None:
sum = 0
for i in range(1, num):
rem = num % i
if rem == 0:
sum = sum + i
if sum == num:
print("Perfect Number")
else:
print("Not Perfect Number")
X = int(input())
checkPerfect(X)
Q3.
Statement Count the prime numbers in a given range A to B (both inclusive) having
even digits sum.
Input Two lines of input, first line contains A and second line contains B.
Format
Output Count of prime numbers in range A to B which have an even digit sum.
Format
Constraint 1 < range < 100
Sample 10
Input 1 25
Sample 4
Output 1
Explanation Prime numbers between 10 and 25 are 11, 13, 17, 19, 23. But out of these
five primes, only four primes (11, 13, 17, and 19) are having even digit sum.
23, has an odd digit sum (2 + 3 = 5).
Test Case 30
Input 1 40
Test Case 2
Output 2
Test Case 10
Input 2 20
Test Case 4
Output 2
Test Case 20
Input 3 30
Test Case 0
Output 3
Test Case 30
Input 4 50
Test Case 2
Output 4
Test Case 50
Input 5 95
Test Case 5
Output 5
Code import math
def isPrime(num: int) -> bool:
if num == 1:
return False
for val in range(2, (int)(math.sqrt(num)) + 1):
if (num % val) == 0:
return False
return True
def sumOfDigits(num: int) -> int:
sum = 0;
while num > 0:
sum += num % 10
num //= 10
return sum;
def countEvenSumPrimes(start: int, end: int) -> int:
count = 0
for i in range(start, end + 1):
if isPrime(i) and sumOfDigits(i) % 2 == 0:
count += 1
return count
start = int(input())
end = int(input())
print(countEvenSumPrimes(start, end))
Q4.
Statement Given a positive number X. Find all jumping numbers smaller than or equal
to X. A number is called a jumping number if all adjacent digits in it differ by
only 1. All single digit numbers are considered as jumping numbers.
Input Single line of input containing the value of X.
Format
Output Output all the jumping numbers in sorted order.
Format
Constraint 1 <= X <= 10^4
Sample 50
Input 1
Sample 0 1 2 3 4 5 6 7 8 9 10 12 21 23 32 34 43 45
Output 1
Explanation 0 to 9 are all single digit numbers. They all are considered jumping
numbers. The difference between any two subsequent digits of other
numbers is 1. For example, in 12, 1 and 2 differ by 1, and in 32, 3 and 2
differ by 1. Therefore they are considered jumping numbers. Whereas, in
24, 2 and 4 differ by 2, hence they are not considered jumping numbers.
Test Case 5
Input 1
Test Case 012345
Output 1
Test Case 15
Input 2
Test Case 0 1 2 3 4 5 6 7 8 9 10 12
Output 2
Test Case 200
Input 3
Test Case 0 1 2 3 4 5 6 7 8 9 10 12 21 23 32 34 43 45 54 56 65 67 76 78 87 89 98 101
Output 3 121 123
Test Case 2000
Input 4
Test Case 0 1 2 3 4 5 6 7 8 9 10 12 21 23 32 34 43 45 54 56 65 67 76 78 87 89 98 101
Output 4 121 123 210 212 232 234 321 323 343 345 432 434 454 456 543 545 565
567 654 656 676 678 765 767 787 789 876 878 898 987 989 1010 1012
1210 1212 1232 1234
Test Case 5000
Input 5
Test Case 0 1 2 3 4 5 6 7 8 9 10 12 21 23 32 34 43 45 54 56 65 67 76 78 87 89 98 101
Output 5 121 123 210 212 232 234 321 323 343 345 432 434 454 456 543 545 565
567 654 656 676 678 765 767 787 789 876 878 898 987 989 1010 1012
1210 1212 1232 1234 2101 2121 2123 2321 2323 2343 2345 3210 3212
3232 3234 3432 3434 3454 3456 4321 4323 4343 4345 4543 4545 4565
4567
Code def isJumpingNumber(num: int) -> bool:
while True:
digit1 = num % 10
num = num // 10
if num == 0:
return True
digit2 = num % 10
if abs(digit1 - digit2) != 1:
return False
def jumpingNumbers(X: int) -> list[int]:
res = []
for i in range(X + 1):
if isJumpingNumber(i) == True:
res.append(i)
return res
X = int(input())
print(*jumpingNumbers(X))