Problem Solving Set I
Problem Solving Set I
Program is very simple, Given two integers A and B, write a program to add these two numbers.
Input
The first line contains an integer T, total number of test cases. Then follow T lines, each line contains two
Integers A and B.
Output
Add A and B and display it.
Constraints
1 ≤ T ≤ 1000
1 ≤ A,B ≤ 10000
Example
Input
3
12
100 200
10 40
Output
3
300
50
2. ATM
Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the transaction
if X is a multiple of 5, and Pooja's account balance has enough cash to perform the withdrawal transaction
(including bank charges). For each successful withdrawal the bank charges 0.50 $US. Calculate Pooja's
account balance after an attempted transaction.
Input
Positive integer 0 < X <= 2000 - the amount of cash which Pooja wishes to withdraw.
Nonnegative number 0<= Y <= 2000 with two digits of precision - Pooja's initial account balance.
Output
Output the account balance after the attempted transaction, given as a number with two digits of precision.
If there is not enough money in the account to complete the transaction, output the current bank balance.
Output:
89.50
Output:
120.00
Output:
120.00
Input
The input begins with two positive integers n k (n, k<=107). The next n lines of input contain one positive
integer ti, not greater than 109, each.
Output
Write a single integer to output, denoting how many integers ti are divisible by k.
Example
Input:
73
1
51
966369
7
9
999996
11
Output:
4
4. Small factorials
You are asked to calculate factorials of some small positive integers.
Input
An integer t, 1<=t<=100, denoting the number of test cases, followed by t lines, each containing a single
integer n, 1<=n<=100.
Output
For each integer n given at input, display a line with the value of n!
Example
Sample input:
4
1
2
5
3
Sample output:
1
2
120
6
5. Sum of Digits
You're given an integer N. Write a program to calculate the sum of all the digits of N.
Input
The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an
integer N.
Output
Calculate the sum of digits of N.
Constraints
1 ≤ T ≤ 1000
1 ≤ N ≤ 1000000
Example
Input
3
12345
31203
2123
Output
15
9
8
Input
t – the number of numbers in list, then t lines follow [t <= 10^6].
Each line contains one integer: N [0 <= N <= 10^6]
Output
Output given numbers in non decreasing order.
Example
Input:
5
5
3
6
7
1
Output:
1
3
5
6
7
7. Number Mirror
Problem Statement
Write a program that accepts a number, n, and outputs the same.
Input
The only line contains a single integer.
Output
Output the answer in a single line.
Constraints
0 ≤ n ≤ 105
Sample Input
123
Sample Output
123
8. Find Remainder
Write a program to find the remainder when two given numbers are divided.
Input
The first line contains an integer T, total number of test cases. Then follow T lines, each line contains two
Integers A and B.
Output
Find remainder when A is divided by B.
Constraints
1 ≤ T ≤ 1000
1 ≤ A,B ≤ 10000
Example
Input
3
12
100 200
10 40
Output
1
100
10
1 140 82
2 89 134
3 90 110
4 112 106
5 88 90
The total scores of both players, the leader and the lead after each round for this game is given below:
Round Player 1 Player 2 Leader Lead
1 140 82 Player 1 58
Input
The first line contains an integer T, total number of test cases. Then follow T lines, each line contains an
integer N.
Output
Display the sum of first and last digit of N.
Constraints
1 ≤ T ≤ 1000
1 ≤ N ≤ 1000000
Example
Input
3
1234
124894
242323
Output
5
5
5
Input
The first line of input consists of a single integer T, denoting the number of integers in Kostya's list.
Then, there are T lines, each of them contain a single integer from the list.
Output
Output T lines. Each of these lines should contain the number of occurences of the digit 4 in the respective
integer from Kostya's list.
Constraints
1 ≤ T ≤ 105
(Subtask 1): 0 ≤ Numbers from the list ≤ 9 - 33 points.
(Subtask 2): 0 ≤ Numbers from the list ≤ 109 - 67 points.
Example
Input:
5
447474
228
6664
40
81
Output:
4
0
1
1
0