The Prime Numbers
MishraJi, a mathematics teacher, was teaching his 6th standard students about the prime
numbers. He listed the first 15 prime numbers on the blackboard:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47
"We see that the 13th prime number is 41.", said MishraJi. Little Tinku, fascinated about the
prime numbers, asked, "Sir, what is the 100th prime number?" The teacher, unable to answer the
question then, promised Tinku to tell the answer in the next class.
Task
Your task is to help MishraJi by writing a program which can tell the Nth prime number.
Input
The first line of the input will contain the single positive integer t (1 <= t <= 1000), indicating
the number of test cases to follow. The following t lines will be containing one positive integer n
per line (1<= n <= 100000).
Output
The output will consist of t lines, with exactly one number on each line, the n-th prime number.
Example
Sample input:
3
13
100
10001
Sample output:
41
541
104743
question 2
The Palindromes
A string is said to be palindrome, if it reads same from both ends, i.e, from left-to-right and from
right-to-left. For example, MALAYALAM is a palindrome string. The letters are symmetrical at
both ends.
Similarly, a numeral palindrome has corresponding digits from the both ends symmetrical. So, on
reversing the digits of the number, we get the same number itself. Thus, 23432 is a palindrome
number. Further, some numbers have the property that they are palindrome in both decimal, and
binary bases. One such example is the number 58510 = 10010010012
We see that both 585 and 1001001001 are palindromes.
Task
In a given range, you have to find out those numbers which are palindrome in both decimal and
binary bases, and report their decimal sum.
Input
The first line of the input will have a single integer t (1 <= t <= 50), the number of test cases. Then,
t test cases will follow. Each test case will consist of two numbers m and n, which will define the
lower limit and the upper limit of the range (m, n <= 10000000 and m < n).
Output
The output will contain t lines with exactly one number on each line, the sum of all the palindromes
(in both decimal and binary bases) that lie in the given range [m, n].
Examples
Sample input:
3
1 100
300 1000
10000 50000
Sample output:
157
1772
89339
question 3
The Language War
Apologists of Java and C++ can argue for hours proving each other that their programming
language is the best one. Java people will tell that their programs are clearer and less prone to
errors, while C++ people will laugh at their inability to instantiate an array of generics or tell them
that their programs are slow and have long source code.
Another issue that Java and C++ people could never agree on is identifier naming. In Java a
multiword identifier is constructed in the following manner: the first word is written starting from
the small letter, and the following ones are written starting from the capital letter, no separators are
used. All other letters are small. Examples of a Java identifier are javaIdentifier,
longAndMnemonicIdentifier, name, nEERC.
Unlike them, C++ people use only small letters in their identifiers. To separate words they use
underscore character _. Examples of C++ identifiers are c_identifier,
long_and_mnemonic_identifier, name (you see that when there is just one word Java and C++
people agree), n_e_e_r_c.
You are writing a translator that is intended to translate C++ programs to Java and vice versa. Of
course, identifiers in the translated program must be formatted due to its language rules
otherwise people will never like your translator.
Task
The first thing you would like to write is an identifier translation routine. Given an identifier, it
would detect whether it is Java identifier or C++ identifier and translate it to another dialect. If it is
neither, then your routine should report an error. Translation must preserve the order of words and
must only change the case of letters and/or add/remove underscores.
Input
The input file consists of several lines that contains an identifier. It consists of letters of the English
alphabet and underscores. Its length does not exceed 100.
Output
If the input identifier is Java identifier, output its C++ version. If it is C++ identifier, output its Java
version. If it is none, output 'Error!' instead.
Example
Sample Input:
the_holy_war_of_languages
anotherExample
input
bad_Style
Sample Output:
theHolyWarOfLanguages
another_example
input
Error!
question 3
The Language War
Apologists of Java and C++ can argue for hours proving each other that their programming
language is the best one. Java people will tell that their programs are clearer and less prone to
errors, while C++ people will laugh at their inability to instantiate an array of generics or tell them
that their programs are slow and have long source code.
Another issue that Java and C++ people could never agree on is identifier naming. In Java a
multiword identifier is constructed in the following manner: the first word is written starting from
the small letter, and the following ones are written starting from the capital letter, no separators are
used. All other letters are small. Examples of a Java identifier are javaIdentifier,
longAndMnemonicIdentifier, name, nEERC.
Unlike them, C++ people use only small letters in their identifiers. To separate words they use
underscore character _. Examples of C++ identifiers are c_identifier,
long_and_mnemonic_identifier, name (you see that when there is just one word Java and C++
people agree), n_e_e_r_c.
You are writing a translator that is intended to translate C++ programs to Java and vice versa. Of
course, identifiers in the translated program must be formatted due to its language rules
otherwise people will never like your translator.
Task
The first thing you would like to write is an identifier translation routine. Given an identifier, it
would detect whether it is Java identifier or C++ identifier and translate it to another dialect. If it is
neither, then your routine should report an error. Translation must preserve the order of words and
must only change the case of letters and/or add/remove underscores.
Input
The input file consists of several lines that contains an identifier. It consists of letters of the English
alphabet and underscores. Its length does not exceed 100.
Output
If the input identifier is Java identifier, output its C++ version. If it is C++ identifier, output its Java
version. If it is none, output 'Error!' instead.
Example
Sample Input:
the_holy_war_of_languages
anotherExample
input
bad_Style
Sample Output:
theHolyWarOfLanguages
another_example
input
Error!
question 4
Maximum Sub-Array
For an array of n integers, the maximum sub-array can be defined as that subset of consecutive
elements of the array, which on addition, yield the maximum sum. For example, if there is an array
A = {8, -10, 7, 4, -3, 5, -9, 2, -4, 3 } ,
then the maximum sub-array whose elements add up to produce maximum sum is { 7, 4, -3, 5 }
with the sum being 13.
Task
Given a set of arrays, your task is to find out their respective maximum sub-arrays, and report the
sum of the elements of each sub-array
Input
The first line of the input will be a positive integer t (1 <= t <= 100000). t lines will follow
representing each of the t test cases. Each of these lines will contain 25 integers, the elements of
each array.
Output
The output should be of t lines, with exactly one number on each line, the sum of the elements of
the corresponding array's maximum sub-array.
Example
Sample input:
3
8 20
22 97
38
15 0 40 0 75 4 50
7 78
52 12 50
77 91 80
49 49
99 40
17
18
8 57 60
87 17 40 98 43
69 48 4
56 62 0 81 49
31 73
55
79 14
29 93
7
40 67 53 88
30 3 49
13 36 65
52 70
95 23
4
60 11
42 69
24 68 56 1 32
5
Sample output:
214
516
261
MishraJi, a mathematics teacher, was teaching his 6th standard students about the prime
numbers. He listed the first 15 prime numbers on the blackboard:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47
"We see that the 13th prime number is 41.", said MishraJi. Little Tinku, fascinated about the
prime numbers, asked, "Sir, what is the 100th prime number?" The teacher, unable to answer the
question then, promised Tinku to tell the answer in the next class.
Task
Your task is to help MishraJi by writing a program which can tell the Nth prime number.
Input
The first line of the input will contain the single positive integer t (1 <= t <= 1000), indicating
the number of test cases to follow. The following t lines will be containing one positive integer n
per line (1<= n <= 100000).
Output
The output will consist of t lines, with exactly one number on each line, the n-th prime number.
Example
Sample input:
3
13
100
10001
Sample output:
41
541
104743
question 2
The Palindromes
A string is said to be palindrome, if it reads same from both ends, i.e, from left-to-right and from
right-to-left. For example, MALAYALAM is a palindrome string. The letters are symmetrical at
both ends.
Similarly, a numeral palindrome has corresponding digits from the both ends symmetrical. So, on
reversing the digits of the number, we get the same number itself. Thus, 23432 is a palindrome
number. Further, some numbers have the property that they are palindrome in both decimal, and
binary bases. One such example is the number 58510 = 10010010012
We see that both 585 and 1001001001 are palindromes.
Task
In a given range, you have to find out those numbers which are palindrome in both decimal and
binary bases, and report their decimal sum.
Input
The first line of the input will have a single integer t (1 <= t <= 50), the number of test cases. Then,
t test cases will follow. Each test case will consist of two numbers m and n, which will define the
lower limit and the upper limit of the range (m, n <= 10000000 and m < n).
Output
The output will contain t lines with exactly one number on each line, the sum of all the palindromes
(in both decimal and binary bases) that lie in the given range [m, n].
Examples
Sample input:
3
1 100
300 1000
10000 50000
Sample output:
157
1772
89339
question 3
The Language War
Apologists of Java and C++ can argue for hours proving each other that their programming
language is the best one. Java people will tell that their programs are clearer and less prone to
errors, while C++ people will laugh at their inability to instantiate an array of generics or tell them
that their programs are slow and have long source code.
Another issue that Java and C++ people could never agree on is identifier naming. In Java a
multiword identifier is constructed in the following manner: the first word is written starting from
the small letter, and the following ones are written starting from the capital letter, no separators are
used. All other letters are small. Examples of a Java identifier are javaIdentifier,
longAndMnemonicIdentifier, name, nEERC.
Unlike them, C++ people use only small letters in their identifiers. To separate words they use
underscore character _. Examples of C++ identifiers are c_identifier,
long_and_mnemonic_identifier, name (you see that when there is just one word Java and C++
people agree), n_e_e_r_c.
You are writing a translator that is intended to translate C++ programs to Java and vice versa. Of
course, identifiers in the translated program must be formatted due to its language rules
otherwise people will never like your translator.
Task
The first thing you would like to write is an identifier translation routine. Given an identifier, it
would detect whether it is Java identifier or C++ identifier and translate it to another dialect. If it is
neither, then your routine should report an error. Translation must preserve the order of words and
must only change the case of letters and/or add/remove underscores.
Input
The input file consists of several lines that contains an identifier. It consists of letters of the English
alphabet and underscores. Its length does not exceed 100.
Output
If the input identifier is Java identifier, output its C++ version. If it is C++ identifier, output its Java
version. If it is none, output 'Error!' instead.
Example
Sample Input:
the_holy_war_of_languages
anotherExample
input
bad_Style
Sample Output:
theHolyWarOfLanguages
another_example
input
Error!
question 3
The Language War
Apologists of Java and C++ can argue for hours proving each other that their programming
language is the best one. Java people will tell that their programs are clearer and less prone to
errors, while C++ people will laugh at their inability to instantiate an array of generics or tell them
that their programs are slow and have long source code.
Another issue that Java and C++ people could never agree on is identifier naming. In Java a
multiword identifier is constructed in the following manner: the first word is written starting from
the small letter, and the following ones are written starting from the capital letter, no separators are
used. All other letters are small. Examples of a Java identifier are javaIdentifier,
longAndMnemonicIdentifier, name, nEERC.
Unlike them, C++ people use only small letters in their identifiers. To separate words they use
underscore character _. Examples of C++ identifiers are c_identifier,
long_and_mnemonic_identifier, name (you see that when there is just one word Java and C++
people agree), n_e_e_r_c.
You are writing a translator that is intended to translate C++ programs to Java and vice versa. Of
course, identifiers in the translated program must be formatted due to its language rules
otherwise people will never like your translator.
Task
The first thing you would like to write is an identifier translation routine. Given an identifier, it
would detect whether it is Java identifier or C++ identifier and translate it to another dialect. If it is
neither, then your routine should report an error. Translation must preserve the order of words and
must only change the case of letters and/or add/remove underscores.
Input
The input file consists of several lines that contains an identifier. It consists of letters of the English
alphabet and underscores. Its length does not exceed 100.
Output
If the input identifier is Java identifier, output its C++ version. If it is C++ identifier, output its Java
version. If it is none, output 'Error!' instead.
Example
Sample Input:
the_holy_war_of_languages
anotherExample
input
bad_Style
Sample Output:
theHolyWarOfLanguages
another_example
input
Error!
question 4
Maximum Sub-Array
For an array of n integers, the maximum sub-array can be defined as that subset of consecutive
elements of the array, which on addition, yield the maximum sum. For example, if there is an array
A = {8, -10, 7, 4, -3, 5, -9, 2, -4, 3 } ,
then the maximum sub-array whose elements add up to produce maximum sum is { 7, 4, -3, 5 }
with the sum being 13.
Task
Given a set of arrays, your task is to find out their respective maximum sub-arrays, and report the
sum of the elements of each sub-array
Input
The first line of the input will be a positive integer t (1 <= t <= 100000). t lines will follow
representing each of the t test cases. Each of these lines will contain 25 integers, the elements of
each array.
Output
The output should be of t lines, with exactly one number on each line, the sum of the elements of
the corresponding array's maximum sub-array.
Example
Sample input:
3
8 20
22 97
38
15 0 40 0 75 4 50
7 78
52 12 50
77 91 80
49 49
99 40
17
18
8 57 60
87 17 40 98 43
69 48 4
56 62 0 81 49
31 73
55
79 14
29 93
7
40 67 53 88
30 3 49
13 36 65
52 70
95 23
4
60 11
42 69
24 68 56 1 32
5
Sample output:
214
516
261