Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
IVth PROGRAMMING CONTEST “Minko Balkanski” May 6, 2006 TASK A. DIVISORS Three different integers A, B and C are given (1 < A < B < C < 2000). Write a program div to find the number of integers between 1 and N (1 < N < 1 000 000 000) that are not divisible by any of the numbers A, B and C. The program has to read the numbers A, B, C and N, separated by intervals, from the single line of the standard input (the keyboard). The result has to be printed on the standard output (the screen). EXAMPLE Input 2 3 4 10 Output 3 TASK B. SUMS A sequence of N positive integers (10 < N < 100 000), each is less than or equal 10000, and a positive integer S (S 100 000 000) are given. Write a program sum to find the minimal length of the subsequence of consecutive elements of the sequence, the sum of which is greater than or equal to S. The program has to read the numbers N and S, separated by an interval, from the first line of the standard input. The elements of the sequence will be given in the second line of the standard input, separated by intervals. The result has to be printed on the standard output. EXAMPLE Input 10 15 5 1 3 5 10 7 4 9 2 8 Output 2 TASK C. VILLAGES The central village of a region (labeled with 0 on the Figure) and the other N villages of the region (labeled with numbers from 1 to N) are connected by M roads. There is at most one road between two different villages and it is possible to go from each village to each other village by a direct road that connects them or by a path passing trough other village(s). If the path from the village I to the village J passes through K other villages we will say that this path is of length K+1. The length of the shortest path between villages I and J is called distance between I and J. Let NL be the number of villages that are in a distance less than or equal to L from the central village. Write a program vil to find the number L (0 L < N) such way that the absolute value | NL – (N + 1– NL) | is as small as possible. The program has to read the numbers N and M from the first line of the standard input (3 N 1000, 3 M 100000). Each of the next M lines will contain two labels of villages that are linked with a road. The program has to print on the single row of the standard output the number | NL – (N +1 – NL)|. EXAMPLE Input 8 12 0 1 1 2 2 4 4 3 3 8 8 1 1 5 5 6 6 0 0 4 8 7 7 6 Good luck! Output 1