Plus
Pin


Problem description Progress
ID 38622. Programmer's Day
Темы: Whole numbers    Cycles    Nested Loops   

Before the celebration of the Day of the programmer, the office of the IT company was decorated with a sequence of numbers of length N, a = {a1, a2, a3, ..., aN}. Bugs Hunter, a member of the testing department, would like to play around with this sequence. In particular, he would like to repeat the following operation as many times as possible.
For every i that satisfies 1<=i<=N, do one of the following: "divide ai by 2" and "multiply ai by 3". You can't do "multiply ai by 3" immediately for each i during one operation, the value of ai after any action must be an integer. 
Bugs Hunter does one operation in 1 second, regardless of the number of numbers in the sequence. Determine the maximum time after which Bugs Hunter will return to his work?

Input
The first line contains an integer N (1<=N<=10000). The second line contains N integers ai (1<=ai<=109).

Imprint
Print one number -  the maximum number of seconds after which Bugs Hunter will return to his job.
 

 

Examples
# Input Output Explanation
1 3
5 2 4
3 The sequence is originally 5,2,4.
Three operations can be performed as follows:
- first multiply a1 by 3, multiply a2 by 3 and divide a3 by 2. Now the sequence is 15,6,2;
- then multiply a1 by 3, divide a2 by 2 and multiply a3 by 3. Now the sequence is 45,3,6;
- finally multiply a1 by 3, multiply a2 by 3 and divide a3 by 2. Now the sequence is 135,9,3.
Further, with each number, you can only perform multiplication by 3, but this action is not allowed for all numbers ai at once.
So the answer is 3.
2 4
631 577 243 199
0  
3 10
2184 2126 1721 1800 1024 2528 3360 1945 1280 1776
39  

 

ID 18728. Trolleybuses
Темы: Nested Loops    Simple puzzles   

Trolleybuses of the same route pass through the stop every k (1<=k<=500) minutes. The arrival times of passengers at this stop are known. If a passenger arrives at a stop at the moment when a trolleybus arrives, then he has time to leave on it.
 
Write a program that determines what time the first trolleybus should go (this is a time from 0 to k-1) so that:
1) The total waiting time for a trolleybus for all passengers was minimal.
2) The maximum of the trolleybus waiting times was the minimum.
 
Input
The line contains the number k first, then the number N (0<=N<=100000). Then comes N numbers that specify the times of arrival of passengers 
to stop. Each of these numbers is an integer from 0 to 100000.
 
Output
Write down two numbers that are the answers to the first and second questions of the problem, respectively. 
If there are multiple solutions, print any of them.

Examples
# Input Output
1
100 5
0 210 99 551 99
10
51
 
 

ID 39270. Conclusion
Темы: Nested Loops   

Given the numbers N and m, display the number m as a table of size NxN.

Input
The input is two natural numbers N and (N <= 100, m <= 100).

Imprint
Display the number m as a table of size NxN.
 

Examples
# Input Output
1 3 5 5 5 5
5 5 5
5 5 5

ID 39271. Conclusion
Темы: Nested Loops   

Given a number N and M, display the numbers in the form of a table of size NxM (N lines by M numbers per line):
1 1 1 ... 1
2 2 2 ... 2
3 3 3 ... 3
...


Input
The input is two natural numbers N and (N, M <= 100).

Imprint
Display the numbers as a table of size NxM.
 

Examples
# Input Output
1 3 5 1 1 1 1 1 
2 2 2 2 2 
3 3 3 3 3 

ID 39272. Conclusion
Темы: Nested Loops   

Given a number N and M, display the numbers in the form of a table of size NxM (N lines by M numbers per line):
10 10 10 ... 10
20 20 20 ... 20
30 30 30 ... 30
...


Input
The input is two natural numbers N and (N, M <= 100).

Imprint
Display the numbers as a table of size NxM.
 

Examples
# Input Output
1 3 5 10 10 10 10 10 
20 20 20 20 20
30 30 30 30 30  

ID 39273. Conclusion
Темы: Nested Loops   

Using nested loops in your program, print the numbers in the form of the following table:
12 12 12 12
22 22 22 22
32 32 32 32
...
82 82 82 82

 

ID 39274. Conclusion
Темы: Nested Loops   

Using nested loops in your program, print the numbers in the form of the following table:
2 3 4 ... 20
2 3 4 ... 20
2 3 4 ... 20
2 3 4 ... 20
2 3 4 ... 20
2 3 4 ... 20
2 3 4 ... 20

ID 39275. Conclusion
Темы: Nested Loops   

Using nested loops in your program, print the numbers in the form of the following table:
15 14 13 ... 3
15 14 13 ... 3
15 14 13 ... 3
15 14 13 ... 3
15 14 13 ... 3
15 14 13 ... 3
15 14 13 ... 3
15 14 13 ... 3
15 14 13 ... 3
15 14 13 ... 3

ID 39276. Conclusion
Темы: Nested Loops   

Using nested loops in your program, print the numbers in the form of the following table:
0 0 0 0 0 0
0 0 0 0 0
0 0 0 0
0 0 0
0 0

ID 39277. Conclusion
Темы: Nested Loops   

Using nested loops in your program, print the numbers in the form of the following table:
8 7 6 5 4 3 2 1
8 7 6 5 4 3 2
8 7 6 5 4 3
...
8

ID 39278. Conclusion
Темы: Nested Loops   

Using nested loops in your program, print the numbers in the form of the following table:
2 3 4 5 6 7 8 9 10
3 4 5 6 7 8 9 10
4 5 6 7 8 9 10
...
9 10

 

ID 39279. Conclusion
Темы: Nested Loops   

Using nested loops in your program, print the numbers in the form of the following table:
2
23
2 3 4
2 3 4 5
...
2 3 4 5 6 7 8 9 10  

ID 39280. Conclusion
Темы: Nested Loops   

Using nested loops in your program, print the numbers in the form of the following table:
3 3 3 3 
4 4 4 4 4 
5 5 5 5 5 5 
6 6 6 6 6 6 6 
...
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15

ID 39281. Conclusion
Темы: Nested Loops   

Using nested loops in your program, print the numbers in the form of the following table:
21
22 22
23 23 23
24 24 24 24
...
30 30 30 30 ... 30 30

 

ID 39282. Conclusion
Темы: Nested Loops   

Using nested loops in your program, print the numbers in the form of the following table:
1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3
...
7 ... 7

 

ID 39283. Conclusion
Темы: Nested Loops   

Using nested loops in your program, print the numbers in the form of the following table:
5 10 15 20 25 30 35 40
10 15 20 25 30 35 40
15 20 25 30 35 40
...
35 40
40

 

ID 39284. Conclusion
Темы: Nested Loops   

Using nested loops in your program, print the numbers in the form of the following table:
51 52 53 ... 58
41 42 43 ... 48
...
11 12 13 ... 18

ID 34768. Ladder
Темы: Nested Loops   

Given a natural number n<=9. Output a ladder from n steps, i-th step consists of numbers from 1 to i without spaces.

Input
Enter a natural number.
 
Imprint 
Print the answer to the problem.
 
Examples
# Input Output
1 3 1
12
123

ID 38630. Gromozeka number
Темы: Whole numbers    Nested Loops   

Let S(n) denote the sum of the digits of in decimal notation. For example, S(123) = 1 + 2 + 3 = 6. We will call an integer n a Gromozeki number if for all positive integers m such that m > ; n, the condition \(\frac {S(n)}n <= \frac {S(m)}m\) is satisfied. Given an integer K, list the K of the smallest Gromozeka numbers.

Input
The input is an integer K (K>=1, the K-th smallest Gromozeka number is not greater than 1015).

Imprint
Output K lines. The i-th line should contain the i-th lowest Gromozeka number.
 

 

Examples
# Input Output
1 10 1
2
3
4
5
6
7
8
9
19

 

ID 38520. The sum of three integers
Темы: Cycles    Nested Loops   

You are given two integers K and S. Three variables X, Y and Z< /code> take integer values ​​that satisfy the condition \(0<=X,Y,Z<=K\). How many distinct X values ​​are there , Y and Z such that \(X+Y+Z=S\) ?

Input
The input is two integers K (\(2<=K<=2500\)) and S < /code>(\(0<=S<=3\cdot K\)).

Imprint
Print the number of X, Y and Z triples that satisfy the condition.
 

 

Examples
# Input Output Explanations
1 2 2 6 There are six triplets X, Y and Z that satisfy the condition:
X=0, Y=0, Z=2
X=0, Y=2, Z=0
X=2, Y=0, Z=0
X=0, Y=1, Z=1
X=1, Y=0, Z=1
X=1, Y=1, Z=0
2 5 15 1 Only one triple satisfies the condition of the problem:
X=5, Y=5, Z=5

 

ID 34767. *Root to root
Темы: Nested Loops   

For a given natural number m, calculate:

\(x =\sqrt{m+\sqrt{2 \cdot m+...+\sqrt{n \cdot m + . ..}}}\).
Input data 
The input to the program is a natural number m<=100.
 
Output 
Print the value of the specified expression up to 6 significant digits after the decimal point (it is known that this expression consists of an infinite number of nested roots, for all specified m values, of course).
 
Examples
# Input Output
1 2 2.158477

ID 39361. Pair with the highest amount
Темы: Number systems    Nested Loops   

The program input receives pairs of numbers: a natural number N and the base of the number system r, in which the number N is written. The sign of the end of the input is the pair 0 0. Print a pair of numbers with the maximum sum on the screen. Display numbers in decimal notation. In this problem, by a pair we mean two numbers located side by side.

Input
The input is an unknown number of lines. Each line, except the last one, contains 2 numbers: N (1 <= N <= 107) and r (2 <= N <= 9). The last line contains a pair of 0 0 (a sign of the end of input).

Imprint
Print the answer  a pair of numbers with the maximum sum. If there are several such pairs, print the first one.
 

Examples
# Input Output Explanation
1 3 5
21 4
1 3
18
23
0 0
3 9 In the source data we have the following numbers
35, 214, 13, 18, 23< br /> The pairs are as follows:
(35, 214), (214, 13), (13 , 18), (18, 23)
The pair with the highest sum (35, 214). In decimal notation, these are numbers (3, 9)
Answer: 3 9

ID 42230. Large chess board
Темы: Nested Loops   

The tiles are aligned to N horizontal rows and N vertical columns. Each tile has a grid with A horizontal rows and B vertical columns. All tiles form a square with (A×N) horizontal lines and (B×N) in vertical columns.
For 1<= i, j<= N tile (ij) designates the tile in the i-th row from the top and the j-th column from the left.

Each X square is colored as follows.

  • Each tile is either a white tile or a black tile.
  • Each square in a white tile is colored white; each square in a black tile is colored black.
  • Tile (11) is a white tile.
  • The two tiles that share the same side have different colors. Tile (ab) and tile (cd), have one common side if and only if |a-c|+|b-d|=1 (where |x| denotes the absolute value of < code>x).
Print the X square in the format specified in format.

Input
The program receives three integers as input: N, A, B (1 <= N, A, B <= 10).

Imprint
Print (A×N) strings S1,...,SAxN that satisfy the following conditions.
Each of the strings S1,...,SAxN is a string of length (B× N) consisting of . and #.
For each value i and j (1<= i <= A×N,1 <= j <= B×N) jth character of the string Si is the character . if the square is in the ith string top and left j-th column in X square is colored white; symbol # if the square is black.
 
 
Examples
# Input Output
1
4 3 2
..##..##
..##..##
..##..##
##..##..
##..##..
##..##..
..##..##
..##..##
..##..##
##..##..
##..##..
##..##..
2
5 1 5
.....#####.....#####.....
#####.....#####.....#####
.....#####.....#####.....
#####.....#####.....#####
.....#####.....#####.....
3
4 4 1
.#.#
.#.#
.#.#
.#.#
#.#.
#.#.
#.#.
#.#.
.#.#
.#.#
.#.#
.#.#
#.#.
#.#.
#.#.
#.#.
4
1 4 4
....
....
....
....

ID 42259. Power of Two Generator
Темы: Nested Loops   

The power of two generator works as follows. Every second, starting from the first, it prints on the screen all powers of two whose value does not exceed the current second.
An example of the first numbers that the generator produces:
1
1 2
1 2
1 2 4
...


Given the number n, print the first n numbers that the generator will print on the screen.

Input
The program receives as input number (n <= 103).

Imprint
Print the answer to the problem.
 
 

Examples
# Input Output
1 5 1 1 2 1 2 
2 1 1