473,378 Members | 1,280 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

integer pair search

14
guys i'm to write an application program that gets a filename and number form the command line and print all possible pairs of numbers such that a<b< number and (a^2 +b^2 +1)/ab is an integer

e.g number = 1000
filename = integers.txt

output is
(1,2)
(2,5)
(5,13)
(13,34)
(34,89)
(89,233)
(233,610)

from this example the integer is always three.but the problem is i can't come with an algorith to produce the output.you help will be much appreciated guys
Feb 27 '08 #1
1 1480
chaarmann
785 Expert 512MB
a very simple method is to just loop through each value a=1,2,3,... and b=1,2,3,... and compute the value by given formula. Then see if the result is an integer by comparing
Expand|Select|Wrap|Line Numbers
  1. boolean isInteger = (Math.round(result) == result);.
Or, to avoid float numbers at all,you could calculate
Expand|Select|Wrap|Line Numbers
  1.  int x= (a * a + b * b +1);
  2. int y = a * b;
  3. boolean isInteger = (x % y == 0); 
guys i'm to write an application program that gets a filename and number form the command line and print all possible pairs of numbers such that a<b< number and (a^2 +b^2 +1)/ab is an integer

e.g number = 1000
filename = integers.txt

output is
(1,2)
(2,5)
(5,13)
(13,34)
(34,89)
(89,233)
(233,610)

from this example the integer is always three.but the problem is i can't come with an algorith to produce the output.you help will be much appreciated guys
Feb 27 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: JustSomeGuy | last post by:
in the stl map class I see the use of a function pair and make_pair. What is the difference between pair and make_pair? dictionary.insert(std::pair<Key, Value>(k,v)); works as well as: ...
1
by: jprunier | last post by:
Hi I isolated this code which gives me odd results and I am not sure to understand why. Basically I declared "positions" as a map that I am using to store pairs of integers. The key used for the...
5
by: Eric Lilja | last post by:
As the subject says, which is the proper header to include for the type std::pair? In my program I have a std::vector of std::pair<std::string, std::string> and on my compiler including <vector>...
1
by: jadamson60 | last post by:
>From http://developer.irt.org/script/992.htm ============================================= Q992 How can I accept a name/value pair in the current url and access it as a variable and value? ...
5
by: Nonoize | last post by:
Hi all, Really dumb question but I don't know how to resolve it. Looked in help and evry book I have. I have a table where the primary key was set as an Integer and its reached over 140K...
4
by: Florent Garcin | last post by:
Hello! I would like to use the map structure with a key of Pair<string, string> and an int as the value. Pair is defined as: template <class T1, class T2> class Pair {
4
by: Gary Wessle | last post by:
Hi I am writing a code to open a space delimited data file, return the number of rows and columns, as well as return the nth column where n is user define number. I put all the cells in a...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
21
by: no1zson | last post by:
I do not even know how to correctly ask this question. I have an item field in the code I am about to post. Simple intger meant to be an item number for a cd. The user enters this number. Over the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.