-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGCD.h
More file actions
74 lines (61 loc) · 3.37 KB
/
GCD.h
File metadata and controls
74 lines (61 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/****************************************************
* Title: SLColson21 CSC2400:Program 1 *
* Author: Sharon Colson *
* Date: August 2023 *
* Purpose: Calculate Greatest Common Divisor *
* Using Various Algorithms *
****************************************************/
#ifndef GCD_H
#define GCD_H
#include <iostream>
#include <vector>
using namespace std;
/*------------------------------------------------------------------------
Calculates the greatest common denominator of two integers as well
as the coefficients of Bézout's identity, which are integers x and y
such that:
ax+by=gcd(a,b).
Precondition: Two integers which are the input from the user and
two integers which are passed by reference.
Postcondition: Three integers, the gcd of the user's input and the
calculated coefficients x and y.
-----------------------------------------------------------------------*/
int extendedEuclidGCD(int a, int b,int &x, int &y);
/*------------------------------------------------------------------------
Calculates the greatest common denominator of two integers by checking
all integer values from one to the minimum of the outputs.
Precondition: Two integers which are the input from the user.
Postcondition: One integer, the greatest common denominator for the two
input values.
-----------------------------------------------------------------------*/
int consecutiveIntegerCheckingGCD(int a, int b);
/*------------------------------------------------------------------------
Calculates the greatest common denominator of two integers by creating
a list for each input containing that input's prime factors then
comparing the two lists for common elements. This function utilizes the
factor, commonElements, and GCD functions.
Precondition: Two integers which are the input from the user.
Postcondition: One integer, the greatest common denominator for the two
input values.
-----------------------------------------------------------------------*/
int middleSchoolMethodGCD(int a, int b);
/*------------------------------------------------------------------------
Finds the prime factors for an integer.
Precondition: One integer is given as an argument.
Postcondition: A vector containing the prime factors for the input.
-----------------------------------------------------------------------*/
vector<int> factor(int num);
/*------------------------------------------------------------------------
Finds the common elements in two ordered lists.
Precondition: Two ordered vectors.
Postcondition: A vector containing the common elements from both input
vectors.
-----------------------------------------------------------------------*/
vector<int> commonElements(const vector<int>vector1, const vector<int>vector2);
/*------------------------------------------------------------------------
Calculates the product of a vector of integers.
Precondition: One vector.
Postcondition: An integer product of a vector of integers is returned.
-----------------------------------------------------------------------*/
int GCD(const vector<int> &commonFactors);
#endif