Educational Round #8 — Editorial
Stepan is interested in the greatest common divisor of a pair of numbers, namely GCD(x, y). Given an integer , Stepan wants to know how many pairs of integers exist such that 1 \le i, j \le n and i = GCD(i, j).
Input. One integer n~(1 \le n \le 10^6).
Output. Print the number of such pairs.
1148A group of bandits has hidden a stolen treasure in a room. The door to the room should be unlocked only when it is necessary to take the treasure out. Since the bandits do not trust each other, they want to be able to open the room and take the loot only if at least of them agree to do so.
They decided to install several locks on the door in such a way that it opens only when all the locks are opened. Each lock may have up to keys, distributed among some subset of the bandits. A group of bandits can open a lock if and only if at least one member of the group possesses a key to that lock.
Given the values and , determine the minimum possible number of locks such that, with a proper distribution of keys every group consisting of at least bandits can open all the locks, while no group of smaller size can open all the locks.
For example, when and , it is sufficient to have locks. The keys to lock are given to bandits and , the keys to lock are given to bandits and , and the keys to lock are given to bandits and . No bandit can open all the locks alone, but any group of two bandits can open all of them. It is easy to see that two locks are not sufficient in this case.
Input. The first line contains the number of test cases. Each of the following lines corresponds to one test case and contains two integers n~(1 \le n \le 30) and m~(1 \le m \le n).
Output. For each test case, print the minimum number of required locks on a separate line.
4
3 2
5 1
10 7
5 33
1
210
10Along the beautiful Adriatic coast, there are hotels. Each hotel has its cost in euros.
Petr won euros in the lottery. Now he wants to buy a sequence of consecutive hotels one after another so that the sum of the costs of these consecutive hotels is as large as possible, but does not exceed .
You need to calculate this maximum possible total cost.
Input. The first line contains two integers and m~(1 \le n \le 3 \cdot 10^5, 1 \le m < 2^{31}). The next line contains positive integers less than 10^6, representing the costs of the hotels in the order they are located along the coast.
Output. Print the desired maximum cost (it will be greater than in all tests).
5 12
2 1 3 4 512Probability is often an integral part of computer algorithms. When deterministic algorithms are unable to solve a problem within a reasonable amount of time, probabilistic algorithms come to the rescue. However, in this problem you are not required to design a probabilistic algorithm — you only need to compute the probability that a particular player wins the game.
The game involves players who take turns throwing an object similar to a die (the number of faces is not necessarily six). The players move in order: first the first player, then the second, and so on up to the -th player. If in a given round none of the players wins, the game continues again starting from the first player.
A player wins if, during their turn, a certain event occurs (for example, the number is rolled, a green face appears, and so on), after which the game ends immediately. The probability that this winning event occurs in a single throw is .
Determine the probability that the player with number wins.
Input. The first line contains a single integer t~(t \le 1000) — the number of test cases. Each of the following lines contains three values: the number of players n~(n \le 1000), a real number p~(0 \le p \le 1) — the probability of the winning event in a single throw, and the player number i~(1 \le i \le n) for which the winning probability should be computed.
Output. For each test case, print the probability that the -th player wins. The answer should be printed with exactly digits after the decimal point.
2
2 0.166666 1
2 0.166666 20.5455
0.4545Washing clothes in winter is no easy task, and drying them is even more challenging. But Jane is a clever girl and isn't afraid of routine chores. To speed up the drying process, she decided to use a radiator. However, the radiator is small and can dry only one item at a time.
Jane wants to dry the laundry as quickly as possible. She's asking you to write a program that determines the minimum amount of time needed to dry the entire set of clothes.
Jane has just washed items. During the wash, each item absorbed a_i units of water. Every minute, the amount of water in each item decreases by (as long as the item is not yet dry). Once the amount of water reaches , the item is considered dry and can be packed.
Additionally, each minute, Jane can choose one item and place it on the radiator. The radiator is hot enough that an item placed on it loses units of water per minute (but no more than the amount of water it contains: if an item has less than units of water, it simply dries completely in that minute).
Your task is to determine the minimum amount of time needed to dry all the clothes with optimal use of the radiator. Drying is considered complete when all items are fully dry.
Input. The first line contains one integer n~(1 \le n \le 10^5) — the number of items.
The second line contains integers a_i~(1 \le a_i \le 10^9), where a_i is the amount of water in the -th item after washing.
The third line contains one integer k~(1 \le k \le 10^9) — the evaporation rate of water from an item placed on the radiator (in units of water per minute).
Output. Print one integer — the minimum number of minutes required to completely dry all items.
3
2 3 9
533
2 3 6
52On clear summer days, Nyusha enjoys catching butterflies in the fresh air. But today, she encountered a particularly cunning butterfly — it flew into a labyrinth and tried to hide from her inside.
The labyrinth consists of rooms, numbered from to , some of which are connected by corridors. It is known that there is exactly one simple path between any two rooms, passing only through the corridors. In other words, the labyrinth forms a tree with vertices and n - 1 edges.
The entrance to the labyrinth is located in room number . A leaf is defined as any room connected to exactly one other room and not being the root (i.e., not room ). Each leaf contains an exit from the labyrinth. The butterfly starts its flight from room , heading toward one of the exits. It moves at a constant speed, never turns around, and travels through one corridor per minute, moving to a neighboring room. All corridors are of equal length.
To catch the butterfly, Nyusha decided to enlist the help of some friends. Initially, each of them can take position in any room that contains an exit. As soon as the butterfly begins its journey from the entrance toward some exit, the friends may immediately start moving from their rooms toward the entrance. They move at the same speed as the butterfly. If any of them encounters the butterfly — whether in a room or in the middle of a corridor — it is considered caught. However, if the butterfly reaches an exit without encountering any of the friends, it successfully escapes to freedom.
Help Nyusha determine the minimum number of friends needed to guarantee catching the butterfly, regardless of which exit it chooses.
Input. The first line contains a single integer n~(2 \le n \le 200000) — the number of rooms in the labyrinth.
The following n - 1 lines describe the corridors connecting the rooms. Each line contains two integers and v~(1 \le u, v \le n, u \neq v) — the indices of the rooms connected by a corridor.
It is guaranteed that the given corridor system forms a tree.
Output. Print a single integer — the minimum number of friends required to guarantee that the butterfly will be caught.
3
1 2
1 324
1 2
2 3
2 41A connected graph that contains no cycles is called a tree.
The distance between two vertices of a tree is defined as the length (in edges) of the shortest path connecting them.
Given a tree with vertices and a positive integer , calculate the number of distinct pairs of vertices in the tree whose distance is exactly . Note that the pairs and are considered the same.
Input. The first line contains two integers and k~(1 \le n \le 50000, 1 \le k \le 500) — the number of vertices in the tree and the required distance between vertices.
Each of the following n - 1 lines describes an edge of the tree in the format a_i~b_i~(1 \le a_i, b_i \le n, a_i \ne b_i), where a_i and b_i are the vertices connected by the -th edge. All edges are distinct.
Output. Print one integer — the number of distinct pairs of vertices in the tree whose distance is exactly .

5 2
1 2
2 3
3 4
2 54Let us call a string of length greater than one a palindrome if it reads the same from left to right and from right to left.
A superpalindrome is a string that can be represented as a concatenation of one or more palindromes.
Given a string , find the number of substrings of that are superpalindromes.
Input. One string s~(1 \le |s| \le 1000) consisting of lowercase Latin letters.
Output. Print one integer — the number of substrings of the string that are superpalindromes.
abc0abacdc3
Comments