Armstrong numbers between two intervals
Write a program to print all the Armstrong numbers in the given range
A to B(including A and B). An N-digit number is an Armstrong number if the number equals the sum of the Nth power of its digits.
Input
The first line has an integer
A. The second line has an integer B.
Output
Print all Armstrong numbers separated by a space.
If there are no Armstrong numbers in the given range, print
-1.
Explanation
For
A = 150 and B = 200
For example, if we take number 153, the sum of the cube of digits
1, 5, 3 is
13 + 53 + 33 = 153.
So, the output should be
153.
Sample Input 1
150
200
Sample Output 1
153
Sample Input 2
1
3
Sample Output 2
1 2 3
sample input3
10
15
sample output 3
-1
please provide correct output in sample output 2Hollow Right Triangle - 2
Given an integer number N as input. Write a program to print the hollow right-angled triangular pattern of N lines as shown below.
Note: There is a space after each asterisk (*) character.
Input
The first line of input is an integer N.
Explanation
In the given example the hollow right angled triangle of side
5. Therefore, the output should be
*
* *
* *
* *
* * * * *
Sample Input 1
4
Sample Output 1
*
* *
* *
* * * *
Sample Input 2
5
Sample Output 2
*
* *
* *
* *
* * * * *
Hollow Right Triangle
Given an integer number N as input. Write a program to print the hollow right-angled triangular pattern of N lines as shown below.
Note: There is a space after each asterisk (*) character.
Input
The first line of input is an integer N.
Explanation
In the given example the hollow right angled triangle of side
4. Therefore, the output should be
* * * *
* *
* *
*
Sample Input 1
4
Sample Output 1
* * * *
* *
* *
*
Sample Input 2
6
Sample Output 2
* * * * * *
* *
* *
* *
* *
*
Perfect Squares in a Range
You are given two given numbers, A and B where 1 <= A <= B, Write a program to find the number of perfect squares in the range A to B (including A and B).
Input
The first line of input is an integer A. The second line of input is an integer B.
Explanation
In the given example,
A = 9 and B = 100. The perfect squares in the range A to B are
3 * 3 = 9
4 * 4 = 16
5 * 5 = 25
6 * 6 = 36
7 * 7 = 49
8 * 8 = 64
9 * 9 = 81
10 * 10 = 100
So, the output should be
8.
Sample Input 1
9
100
Sample Output 1
8
Sample Input 2
625
1444
Sample Output 2
14
In the shop there are 3 barbers, Alpha, Beta and Gamma, who are not always efficient as employees. All the customers are seated in a waiting area, each customer has a card which has a unique integral ID.Alpha: He will call either the person with least ID from the waiting area of the one with max ID. Min or Max is decided randomly by him (assume 50% probability for each min or max). Beta: He will choose a ‘k’ and will call the kth smallest ID, (Kth ID when all IDs are arranged in ascending order). K is chosen randomly from the number of persons available in waiting area (1<= K <= Total persons)
Gamma: He will always choose the median ID. If there are ‘n’ people in the waiting area, the median will be defined as (n+1)/2 th ID when all of them are arranged in ascending order. (For both odd and even ‘n’ ). design a data structure which should support the query of each of the three barbers.
Shaded Diamond Given an integer value N as input,write a program to print a shaded diamond of 2*N -1 rows using an asterisk(*) character as shown below.
Sample Input 1
6
Sample Output 1
*
* *
* * *
* * * *
* * * * *
* * * * * *
* *
* *
* *
* *
*
Sample Input 2
5
Sample Output 2
*
* *
* * *
* * * *
* * * * *
* *
* *
* *
*
this code not correct output:
N = int(input())
for i in range(1, N + 1):
for j in range(1, N - i + 1):
print(end = ' ')
for l in range(1, 2 * i):
if l == 1 or l == i * 2 - 1:
print('*', end = '')
else:
print('*', end = '')
print()
for i in range(N - 1, 0, -1):
for j in range(1, N - i + 1):
print(' ', end = '')
for l in range(1, 2 * i):
print()Perfect Squares in a Range
You are given two given numbers, A and B where 1 <= A <= B, Write a program to find the number of perfect squares in the range A to B (including A and B).
Input
The first line of input is an integer A. The second line of input is an integer B.
Explanation
In the given example,
A = 9 and B = 100. The perfect squares in the range A to B are
3 * 3 = 9
4 * 4 = 16
5 * 5 = 25
6 * 6 = 36
7 * 7 = 49
8 * 8 = 64
9 * 9 = 81
10 * 10 = 100
So, the output should be
8.
Sample Input 1
9
100
Sample Output 1
8
Sample Input 2
625
1444
Sample Output 2
14
Sum of 1 series
Given integer N as input. Write a program to print the sum of series 1 + 11 + 111 + .... N terms.
Input
The first line of input is an integer N.
Output
The output should be an integer representing the sum of series.
Given
N = 4The sum for first
4 terms is 1 + 11 + 111 + 1111So the output should be
1234.
Sample Input 1
4
Sample Output 1
1234
Sample Input 2
5
Sample Output 2
12345
Number of digits until N
Given an integer N, write a program that prints the count of the total number of digits between 1 and N.
Input
The input is a positive integer.
The output should be a single line containing the count of the digits up to the given number.
Given
N = 10From 1 to 9, each number contains a single digit. From 10 onwards, the numbers contain two digits.
So the output should be 9 + 2 =
11.
Sample Input 1
10
Sample Output 1
11
Sample Input 2
4
Sample Output 2
4