// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}
// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}
// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}
// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}
// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}
// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}
// C++ program to find GCD of two numbers#include<bits/stdc++.h>usingnamespace std;intstatic dp[1001][1001];// Function to return gcd of a and bintgcd(int a,int b){// Everything divides 0if(a ==0)return b;if(b ==0)return a;// base caseif(a == b)return a;// if a value is already// present in dpif(dp[a][b]!=-1)return dp[a][b];// a is greaterif(a > b)
dp[a][b]=gcd(a-b, b);// b is greaterelse
dp[a][b]=gcd(a, b-a);// return dpreturn dp[a][b];}// Driver program to test above functionintmain(){int a =98, b =56;memset(dp,-1,sizeof(dp));
cout<<"GCD of "<<a<<" and "<<b<<" is "<<gcd(a, b);return0;}
// Iterative Java program to// implement Stein's Algorithmimportjava.io.*;classGFG{// Function to implement Stein's// Algorithmstaticintgcd(int a,int b){// GCD(0, b) == b; GCD(a, 0) == a,// GCD(0, 0) == 0if(a ==0)return b;if(b ==0)return a;// Finding K, where K is the greatest// power of 2 that divides both a and bint k;for(k =0;((a | b)&1)==0;++k){
a >>=1;
b >>=1;}// Dividing a by 2 until a becomes oddwhile((a &1)==0)
a >>=1;// From here on, 'a' is always odd.do{// If b is even, remove// all factor of 2 in bwhile((b &1)==0)
b >>=1;// Now a and b are both odd. Swap// if necessary so a <= b, then set// b = b - a (which is even)if(a > b){// Swap u and v.int temp = a;
a = b;
b = temp;}
b =(b - a);}while(b !=0);// restore common factors of 2return a << k;}// Driver codepublicstaticvoidmain(String args[]){int a =34, b =17;
System.out.println("Gcd of given "+"numbers is "+gcd(a, b));}}// This code is contributed by Nikita Tiwari
// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}
// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}
// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}
// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}
// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}
// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}
// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}
// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}
// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}
// CPP program to illustrate// gcd function of C++ STL#include<iostream>#include<algorithm>// #include<numeric> for C++17usingnamespace std;intmain(){
cout <<"gcd(6, 20) = "<<__gcd(6,20)<< endl;// gcd(2.0,8) for C++17}