Skip to content

Commit fc7a2bd

Browse files
author
Pranjal
authored
Merge pull request royalpranjal#33 from pockemon/master
Largest coprime divisor and fizzbuzz added
2 parents fbb2188 + 1b03fdb commit fc7a2bd

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Math/FizzBuzz.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//see this to check other variations of fizzbuzz: https://www.geeksforgeeks.org/fizz-buzz-implementation/
2+
3+
vector<string> Solution::fizzBuzz(int A) {
4+
vector<string> v;
5+
for(int i=1; i<=A; i++)
6+
{
7+
if(i%15==0)
8+
v.push_back("FizzBuzz");
9+
else if(i%3==0)
10+
v.push_back("Fizz");
11+
else if(i%5==0)
12+
v.push_back("Buzz");
13+
else
14+
v.push_back(to_string(i));
15+
}
16+
return v;
17+
}

Math/LargestCoprimeDivisor.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//reference: https://www.geeksforgeeks.org/largest-number-divides-x-co-prime-y/
2+
//Note: you can write the function for gcd [i'm using inbuilt gcd function in c++]
3+
4+
int Solution::cpFact(int x, int y) {
5+
6+
while (__gcd(x, y) != 1) {
7+
x = x / __gcd(x, y);
8+
}
9+
return x;
10+
}

0 commit comments

Comments
 (0)