You are on page 1of 9

TELOS 2014

CODIFICTION PROBLEMS

Problem 1. SUM IT UP Given N numbers 1, 2, 3, ..., N, your task is to find the value of the expression after placing signs + and between every pair of adjacent digits alternately. For example, if N=12 then the expression becomes +1 -2 +3 -4 +5 -6 +7 -8 +9 -1+0 -1+1 -1+2 and the value of this expression is 5. Input Each line contains one integer number N (1= N = 10^15). Last line contains 0 and shouldn't be processed. Number of lines in the input does not exceed 40. Output For every line in the input write the answer on a separate line. Example Input: 12 0 Output: 5

Problem 2. COMBINATION OF PRIMES A combi-prime is a prime number that is composed of other prime numbers less than the number itself. Example: 1013 is a combi-prime as it consists of 101 and 3 and both are primes less than 1013. But 2003 is not combi-prime as leading zeroes are not allowed. A combi-prime must contain >=2 primes and overlapping not allowed. Input The first line contains an integer T specifying the number of test cases. (T <= 1000) This is followed by T lines, each containing an integer n number 0<=n<=10^9. Output For each test case print single line containing the first integer greater than or equal to n which is a combi-prime. Example Input: 3 10 100 1000 Output: 23 113 1013

Problem 3. OPERATIONS There are N numbers a[0],a[1]..a[N - 1]. Initially all are 0. You have to perform two types of operations: 1 A B which means "Increase the numbers between indices A and B (inclusive) by 1". 3 A B which means "print how many numbers between indices A and B (inclusive) are divisible by 3". Input The first line contains two integers, N and M. Each of the next M lines are either of the form "1 A B" or "3 A B" as mentioned above. Output Output 1 line for each of the queries of the form "3 A B" mentioned above Example Input: 47 103 012 013 100 003 133 103 Output: 4 1 0 2

Problem 4. SMALLEST AMONG ALL You are provided with 2 numeric strings A and B. Now there are several ways of entering B into A. For example, string A is "369", and string B is "4799". There are 4 ways that B can be inserted into A. The result will be the following 4 strings: 4799369, 3479969, 3647999, 3694799 The number smallest amongst these is 3479969 You task is to find the smallest number formed upon entering any given string B into any given A. Input Input contains several cases. Each case has 2 strings A and B with length no longer than 100000 in 2 lines. Process the input until EOF. The strings consist of only digit 1-9. Output For each case, output the minimal possible result. Example Input: 369 4799 666 12345 Output: 3479969 12345666

Problem 5. PRIME TRIANGLE Consider the triangle below. It contains all prime numbers. 2 35 7 11 13 17 19 23 29 ......... Given an integer n (1 < n < 10^8) , print its position in the triangle. Input The first line is the integer T (1<= T <= 10^4) which is the number of test cases. This is followed by T lines each line contain integer 1 <= n <= 10^8. Output Consists if one line. If the number exists, print pair of integers i , j, where i is the row number and j is the column number , 1 base. If n does not exist in the triangle, print -1. Example Input: 3 3 23 4 Output: 21 43 -1

Problem 6. OPERATIONS II You are provided with the following 2 operation that can be performed on a set of N numbers: E x y -> x-th number becomes equal to y. S x y -> Calculate the sum of distinct numbers from x-th to y-th. For example: For the set {1,2,3,2,5}, E 1 3 will result in the set {3,2,3,2,5} For the set {1,2,3,2,5}, S 1 5 will result in 11 (1+2+3+5) Input First line is the integer N (1<=N<=50000) The second line consists of N numbers. Third line is an interger M (1<=M<=100000) The following M lines consist of queries of the form E x y or S x y All numbers in input will fit in the signed 32-bit type. Output Output an answer for every query of type S x y. Example Input: 5 12423 3 S24 E47 S24 Output: 6 13

Problem 7. RIGHT TRIANGLES Given N points in a coordinate plane, write a program which calculates the number of ways a right triangle can be formed by three of the given points. Input The first line of input contains an integer N (3 <= N <= 1500), the number of points. Each of the following N lines contains the coordinates of one point, two integers separated by a space. The coordinates will be between -10^9 and 10^9. No two points will be located at the same coordinates. Output Output the number of right triangles. Example Input: 5 -1 1 -1 0 00 10 11 Output: 7 Input: 4 50 26 86 57 Output: 0

Problem 8. LCM TABLE Consider the below table of N rows and M columns. The number in the ith row and jth column is the LCM of i,j. A table of 4*5 is just like this: 1 2 3 4 2 2 6 4 3 6 3 12 4 4 12 4 5 10 15 20

Your task is to find the sum of all the numbers in the table. Input 2 positive integers N,M (N, M <= 107) Output A positive integer which is the sum of all the numbers in the table Example Input: 45 Output: 122

You might also like