
August 13th, 2013, 11:10 PM
#1
jumble with numbers
In NASA, two researchers, Mathew and John, started their work on a new planet, but while practicing research they faced a mathematical difficulty. In order to save the time they divided their work.
So scientist Mathew worked on a piece and invented a number computed with the following formula:
A Mathew number is computed as follows using the formula:
H(n) = n(2n1)
And scientist John invented another number which is built by the following formula which is called John number.
T(n) = n(n+1)/2
Now Mathew and John are jumbled while combining their work. Now help them combine their research work by finding out number in a given range that satisfies both properties. Using the above formula, the first few MathewJohn numbers are:
1 6 15 28 …
Input Format:
Input consists of 3 integers T1,T2,M separated by space . T1 and T2 are upper and lower limits of the range. The range is inclusive of both T1 and T2. Find Mth number in range [T1,T2] which is actually a MathewJohn number.
Line 1
T1 T2 M,where T1 is upper limit of the range, T2 is lower limit of the range and M ,where Mth element of the series is required
Constraints:
0 < T1 < T2 < 1000000
Output Format:
Print Mth number from formed sequence between T1 and T2(inclusive).
Line 1
For Valid Input,print
Print Mth number from formed sequence between T1 and T2
Or
No number is present at this index
For Invalid Input,print
Invalid Input
Sample Input and Output
SNo. Input Output
1
90 150 2
120
2
20 80 6
No number is present at this index
3
5 3 a
Invalid Input

August 13th, 2013, 11:11 PM
#2
Re: jumble with numbers
plzzzzzz.....give me sollution for this thread...its very urgent...

August 14th, 2013, 04:53 AM
#3
Re: jumble with numbers
Originally Posted by Tejaswi Godavarthi
plzzzzzz.....give me sollution for this thread...its very urgent...
It may be urgent to you, but this has the look of an assignment which if it is we won't be providing a ready made answer for you as that would be classed as cheating. If this is an assigment, have a read of
http://forums.codeguru.com/showthrea...orkassignment
Until you can provide some code for us to comment upon, possibly the best advice we could give is to ask how you would do this without a computer using just pen and paper? Once you know how to do it manually, then that can be expressed as an algorithm and then a program design can be done and finally a program can be coded to implement the algorithm/design.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only  not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums  and not via private messages!
C++17 Compiler: Microsoft VS2019 (16.6.3)

May 19th, 2020, 02:31 AM
#4
Re: jumble with numbers
# Author Pawan
i=1
count=0
try:
listi= list(map(int,input().split(" ")))
except:
print("Invalid Input")
exit()
ll=listi[0]
ul=listi[1]
k=listi[2]
num=0
while num<=ul:
num=i*(2*i1)
# print(num)
if num>=ll and num<=ul:
count=count+1
if count==k:
print(num)
break
i=i+1
if count<k:
print("No number is present at this index")

May 19th, 2020, 02:43 AM
#5
Re: jumble with numbers
Victor Nijegorodov

May 19th, 2020, 02:49 AM
#6
Re: jumble with numbers
the solution to the above question in python

May 19th, 2020, 03:57 AM
#7
Re: jumble with numbers
This is a C++ forum  not a python one!
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only  not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums  and not via private messages!
C++17 Compiler: Microsoft VS2019 (16.6.3)

May 19th, 2020, 04:18 AM
#8
Re: jumble with numbers
Originally Posted by coder07
the solution to the above question in python
The sample inputs and outputs are easier to understand if formatted like this i think,
SNo / Input / Output

1 / 90 150 2 / 120
2 / 20 80 6 / No number is present at this index
3 / 5 3 a / Invalid Input
The brute force solution must be to generate two lists, one for Mathew numbers and one for John numbers, of all n within the given range. The lists are then scanned for equal numbers, that is MathewJohn numbers. Finally the M'th MathewJohn number is chosen.
Finding equal numbers in two sorted lists is a standard O(N) problem (two pointers are advanced successively). Since the Mathew and John numbers appear in sorted order no actual list data structures are necessary.
Last edited by wolle; May 19th, 2020 at 05:56 AM.

May 19th, 2020, 06:22 AM
#9
Re: jumble with numbers
Finding equal numbers in two sorted lists is a standard O(N) problem (two pointers are advanced successively). Since the Mathew and John numbers appear in sorted order no actual list data structures are necessary.
std::set_intersection() could be used.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only  not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums  and not via private messages!
C++17 Compiler: Microsoft VS2019 (16.6.3)

May 19th, 2020, 07:13 AM
#10
Re: jumble with numbers
For H, given a lower limit of x ie n(2n1) > x, then the starting point of n is given by
n = int((1 + sqrt(1 + 8x))/4)
Similarly for T, given a lower limit of y ie n(n+1)/2 > y, then the starting point is given by
n = int((1 + sqrt(1 + 8y))/2)
This avoids needles computations and matches. Obviously when T(n) and H(n) exceed the upper limit, then also the computations for that set also stop.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only  not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums  and not via private messages!
C++17 Compiler: Microsoft VS2019 (16.6.3)

May 19th, 2020, 08:02 AM
#11
Re: jumble with numbers
Originally Posted by 2kaud
For H, given a lower limit of x ie n(2n1) > x, then the starting point of n is given by
n = int((1 + sqrt(1 + 8x))/4)
Similarly for T, given a lower limit of y ie n(n+1)/2 > y, then the starting point is given by
n = int((1 + sqrt(1 + 8y))/2)
This avoids needles computations and matches. Obviously when T(n) and H(n) exceed the upper limit, then also the computations for that set also stop.
This thread is from 2013
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
OnDemand Webinars (sponsored)
