JS - Mock Exam 1
JS - Mock Exam 1
Crooked Digits
The crooked digit of a given number N is calculated using the number's digits in a very weird and bendy
algorithm. The algorithm takes the following steps:
Sums the digits of the number N and stores the result back in N.
If the obtained result is bigger than 9, step 1. is repeated, otherwise the algorithm finishes.
Input
The only line in the input contains a number N, which can be an integer or real number (decimal
fraction), positive or negative.
The input data will always be valid and in the format described. There is no need to check it explicitly.
Output
You must print the calculated crooked digit of the number N on the first and only line of the output.
Constraints
The number N will have no more than 300 digits before and after the decimal point.
Sample tests
Input
Output
Input
-7231
Output
4
Input
1020340567.89
Output
Prime Triangle
We know that you love math, so we have prepared a very interesting task, that involves both geometry
and prime numbers.
By a given N number, from which you need to generate a sequence of 1 to N inclusive. For every prime
number in that sequence, you need to print out all the other numbers before it (and the number itself),
whether they are prime or not
Example
Result:
12
123
12345
1234567
Final result:
11
111
11101
1110101
Input
Output
The output should consist of several lines of digits each of which can be either 1 or 0
Sample tests
Input
10
Output
11
111
11101
1110101
Input
27
Output
11
111
11101
1110101
11101010001
1110101000101
11101010001010001
1110101000101000101
11101010001010001010001
Constraints
The input data will always be valid and in the format described. There is no need to check it explicitly
Balanced Numbers
A balanced number is a 3-digit number whose second digit is equal to the sum of the first and last digit.
Write a program which reads and sums balanced numbers. You should stop when an unbalanced
number is given.
Input
Output
Constraints
Sample tests
Input
132
123
Output
132
Input
275
693
110
742
Output
1078