From f4e1f7f58a2f0ff66462ebc8a16d2a0b32dbc7b3 Mon Sep 17 00:00:00 2001 From: aniakubik Date: Fri, 25 Oct 2019 17:42:51 +0200 Subject: [PATCH 1/3] extended eucildean algorithm --- Math/extendedEuclidian.cpp | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Math/extendedEuclidian.cpp diff --git a/Math/extendedEuclidian.cpp b/Math/extendedEuclidian.cpp new file mode 100644 index 000000000..ad9846a87 --- /dev/null +++ b/Math/extendedEuclidian.cpp @@ -0,0 +1,51 @@ +#include +#include + +using namespace std; + +/* + for numbers a, b returns x, y such as x * a + y * b = gcd(a,b) +*/ + +pair extendedEuclidian(int a, int b) { + int a_old = a, b_old = b; + if(a < b) swap(a,b); + + int x = 0, y = 1, old_x = 1, old_y = 0; + + int quotient, residue; + while (b) { + quotient = a / b; + residue = a % b; + + a = b; + b = residue; + + int temp; + + temp = x; + x = old_x - quotient * x; + old_x = temp; + + + temp = y; + y = old_y - quotient * y; + old_y = temp; + } + + if(b_old > a_old) swap(old_x, old_y); + + return make_pair(old_x, old_y); + +} + +int main() { + + int a, b; + cin >> a >> b; + pair result = extendedEuclidian(a, b); + + cout<< result.first << " " << result.second; + + +} \ No newline at end of file From 56cfe3f041a3dc65ccbe18ef0783ad73b19a207c Mon Sep 17 00:00:00 2001 From: aniakubik Date: Tue, 29 Oct 2019 22:26:55 +0100 Subject: [PATCH 2/3] added euler totient function --- Math/eulerTotient.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Math/eulerTotient.cpp diff --git a/Math/eulerTotient.cpp b/Math/eulerTotient.cpp new file mode 100644 index 000000000..c71219641 --- /dev/null +++ b/Math/eulerTotient.cpp @@ -0,0 +1,37 @@ +#include +#include +using namespace std; + +/* +this function calculate euler totien function +*/ + +long long eulerTotient(long long n){ + + if(n == 1) return 1; + long long result = 1LL; + long long temp = n; + for(int i = 2; i <= floor(sqrt(n)) + 10; i++) { + if( temp % i == 0) { + int j = 0; + while(temp % i == 0){ + j ++; + temp /= i; + } + result = result * pow(i,j-1) * (i-1); + } + } + + if(temp == n){ + return n-1; + } + + return result; +} + +int main(){ + long long n; + cin >> n; + cout << eulerTotient(n); + +} \ No newline at end of file From 8f3efd170fe447dbc5b15593020f9b574020fc3d Mon Sep 17 00:00:00 2001 From: nikhil kala Date: Fri, 17 Apr 2020 18:27:25 +0530 Subject: [PATCH 3/3] Delete eulerTotient.cpp already present --- Math/eulerTotient.cpp | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 Math/eulerTotient.cpp diff --git a/Math/eulerTotient.cpp b/Math/eulerTotient.cpp deleted file mode 100644 index c71219641..000000000 --- a/Math/eulerTotient.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -using namespace std; - -/* -this function calculate euler totien function -*/ - -long long eulerTotient(long long n){ - - if(n == 1) return 1; - long long result = 1LL; - long long temp = n; - for(int i = 2; i <= floor(sqrt(n)) + 10; i++) { - if( temp % i == 0) { - int j = 0; - while(temp % i == 0){ - j ++; - temp /= i; - } - result = result * pow(i,j-1) * (i-1); - } - } - - if(temp == n){ - return n-1; - } - - return result; -} - -int main(){ - long long n; - cin >> n; - cout << eulerTotient(n); - -} \ No newline at end of file