0% found this document useful (0 votes)
223 views

PROBLEM-SET (27 Aug 2011) 1. Finding Pair

The document describes 5 problem sets: 1. Counting pairs in an array that sum to a given value K. 2. Finding the sum of exponent values when writing a number N as a product of prime factors. 3. Counting numbers between 1 and a given value N that contain only lucky digits 3, 7, 9. 4. Finding the sum of the largest odd divisors of numbers between 1 and a given value N. 5. Answering queries by summing subarrays between given indices of a given array, and reporting the total sum.

Uploaded by

FlyingAnt
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
223 views

PROBLEM-SET (27 Aug 2011) 1. Finding Pair

The document describes 5 problem sets: 1. Counting pairs in an array that sum to a given value K. 2. Finding the sum of exponent values when writing a number N as a product of prime factors. 3. Counting numbers between 1 and a given value N that contain only lucky digits 3, 7, 9. 4. Finding the sum of the largest odd divisors of numbers between 1 and a given value N. 5. Answering queries by summing subarrays between given indices of a given array, and reporting the total sum.

Uploaded by

FlyingAnt
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4

PROBLEM- SET( 27 Aug 2011) 1.

Finding Pair
Given an array A of N integers, and an integer K, find the number of pairs (i,j) such that i< j and A[i] + A[j] == K. 2 <= N <= 100000, -10^6 <= A[i], K <= 10^6. Time limit : 2s Input : first line contain N size of array(2 <= N <= 100000) next line contain N integer separated by spaces. last line contain k (-10^6 <= k <= 10^6) Output : Print the answer in a single line, followed by a new line ('\n') Note : '\n' at the end of output in sample cases is just to make sure you print a new line after the answer, no need to display '\n' in output. Sample case : input: 5123455 output: 2\n input: 5 1 -1 3 2 4 3 output: 2\n

------------------------------------------------------------------------------------------------------------

2. Prime Factorization
Given a number N, do prime factorization so that N = p1^e1 * p2^e2 * ... * pk^ek. Print the sum of the powers (e1+e2+...+ek). Input Constraints : 2 <= N <= 10^8. Time limit : 2s

Input: N Output :Print the answer in a single line, followed by a new line ('\n') Note : '\n' at the end of output in sample cases is just to make sure you print a new line after the answer, no need to display '\n' in ouput. Sample Case: Input: 12 Output: 3 Explanation : 12 = 2^2*3^1 so e1 = 2 and e2 = 1 so e1+e2 = 3 ------------------------------------------------------------------------------------------------------------

3. Lucky Numbers
Having taken APS course and attended 4 labs already, you soon relaized that you need more luck in addition to problem solving skills :). The astrologer you met in Indranagar told you that 3, 7, and 9 are your lucky digits. A lucky number for you is a number that contains only your lucky digits in it. For eg: 3, 79, 933 etc., are lucky, where as 372, 91, 70 are not. Given a large integer N, count the number of lucky numbers in [1,..,N] Input : Only one line having an integer N ( 1 <= N <= 10^14 ) Output : Number of lucky numbers in [1,..,N] followed by a '\n' ( just print '\n', no need to display on screen ) Time Limit : 2s Sample cases :

Input: 78 Output: 8\n Explanation: The lucky numbers not more than 78 are 3, 7, 9, 33, 37, 39, 73, 77

Input: 1000 Output: 39\n

4. Odd Divisor
Let F(x) be the largest positive odd integer that divides x. Given N, find the value of F(1) + F(2) + ... + F(N)

Input : Only one line having an integer N ( 1 <= N <= 10^9 ) Output : Print the answer followed by a '\n' ( just print '\n', no need to display on screen ) Time Limit : 1s Sample cases : Input: 3 Output: 5\n Explanation: F(1) = 1, F(2) = 1, F(3) = 3 Input: 7 Output: 21\n

5. Sum Queries
You are given an array A[0,..,n-1] of n integers. Can you answer the following query ? Find the sum of all elements between indices i and j i.e., A[i] + A[i+1] + ... + A[j-1] + A[j]. Wait, we are not going to leave you with just one query, we will ask you many such queries, Q of them. Read Input section for more details.

Input : First line has an integer N, number of elements in the array A. Second line has N integers of the array A, separated by spaces. Third line has integer Q, number of queries to follow. Each of the next Q lines contains two indices i and j, separated by space. Output : For each of the Q queries, find the value of A[i] + A[i+1] + ... + A[j]. You dont have to output this for each query, just sum the answers for all the queries and output this total sum in one line. Also, print the answer followed by a '\n' ( just print '\n', no need to display on screen ) Constraints : 1 <= N <= 100000, 1 <= Q <= 100000, -1000 <= A[i] <= 1000 and 0 <= i <= j < N

Time Limit : 2s Sample cases : Input: 4 1234 3 01 13 33 Output: 16\n Explanation: Sum(0..1) = 1 + 2 = 3 Sum(1..3) = 2 + 3 + 4 = 9 Sum(3..3) = 4 Sum of answers to all queries 3 + 9 + 4 = 16

You might also like