473,397 Members | 2,028 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,397 software developers and data experts.

Greatest Common Divisor

72
Was wondering if there is an inbuilt function to find the GCD of 2 numbers.
I know BigInteger has one and would like to know if there is one for Integers.

Would prefer to use an inbuilt function if there is one over witting my own which runs the risk or errors.

Thanks in Advance :)
Nov 13 '07 #1
4 2341
r035198x
13,262 8TB
Was wondering if there is an inbuilt function to find the GCD of 2 numbers.
I know BigInteger has one and would like to know if there is one for Integers.

Would prefer to use an inbuilt function if there is one over witting my own which runs the risk or errors.

Thanks in Advance :)
No there is no "inbuilt function" that works on integers.
You do know that you can wrap an integer in a BigInteger, right?
P.S You shouldn't be afraid of writting your own functions (if they are not available). Especially if you are learning the language.
Nov 13 '07 #2
KWSW
72
No there is no "inbuilt function" that works on integers.
You do know that you can wrap an integer in a BigInteger, right?
P.S You shouldn't be afraid of writting your own functions (if they are not available). Especially if you are learning the language.
ok thanks for the reply. Btw would it be more efficient to write my own gcd function or should I wrap the Integer in a BigInteger?
Nov 13 '07 #3
r035198x
13,262 8TB
ok thanks for the reply. Btw would it be more efficient to write my own gcd function or should I wrap the Integer in a BigInteger?
Depends on how you write your own method.
BigInteger's method simply calls MutableInteger's hybridGCD method which uses euclid's algorithm until the numbers are approx the same length before applying the binary algorithm.
You can open the source code for the BigInteger class and have a look at the implementation
Nov 13 '07 #4
KWSW
72
Depends on how you write your own method.
BigInteger's method simply calls MutableInteger's hybridGCD method which uses euclid's algorithm until the numbers are approx the same length before applying the binary algorithm.
You can open the source code for the BigInteger class and have a look at the implementation
i see, think i will use that first until i am done with rest of the program and am feeling adventurous enough.

:)
Nov 13 '07 #5

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

Similar topics

8
by: Mike Nolan | last post by:
As far as I can tell, Postgres has no equivalent to greatest and least functions in Oracle. Yes, you can do the same thing with a case statement, but at the expense of writing MUCH longer SQL...
7
by: Mathew Butler | last post by:
Suppose I have a table t with columns id, col1, col2, col3, col4, col5, col6 all numeric. I want to query the table and for each value of col<x> in the resultset I want to identify the largest value...
21
by: Frederick Gotham | last post by:
I'm trying to devise a compile-time constant for X, where X is the greatest number which satisfies both the following criteria: (1) X <= DESIGNATED_MAX_VALUE (2) X % Y == 0 I'll try to...
7
by: cess | last post by:
Hi!!! i would like to know if what is lacking in the codes below to have a greatest common denominator of two given(by the user) numbers?? I'm confused and i need your help! import java.io.*;...
4
by: sdlt85 | last post by:
Hi, Can someone help me with an idea on how to start writing a C++ code for generating greatest common divisor and the linear combination of two intergers represented as gcd(m, n)= mx + ny and...
15
by: judge82 | last post by:
I'm new to Java and I was looking for some help on this particular problem. I need to create a method that can simplify a fraction, that is, represent it as a fraction where the numerator and the...
2
by: 7asco | last post by:
i want the code of greater common divisor algorithm in c++
3
by: stressedstudent | last post by:
I dont know where I am going wrong so I dont know which part to post, this is what I have, can anyone help me figure out where I am going wrong? THanks for any and all help. // into to c++ //...
35
by: aarklon | last post by:
Hi all, The following question is asked frequently in interviews How to find the greatest of 2 numbers without using relational operators ? the solution i have seen is ( a+b + abs(a-b) )...
4
by: jmf777 | last post by:
Hi I'm trying to write a program to find the greatest common divisor of 2 numbers input by the user. This is what I got so far: #include <stdio.h> int gcd(int a, int b); int main(void) {
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.