From 7af0837f55acae820f0f2a89bd640edfa4572335 Mon Sep 17 00:00:00 2001 From: vaibhavsethia <40268761+vaibhavsethia@users.noreply.github.com> Date: Wed, 17 Oct 2018 18:41:45 +0530 Subject: [PATCH 1/4] Create MathBug_01 --- Math/MathBug_01 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Math/MathBug_01 diff --git a/Math/MathBug_01 b/Math/MathBug_01 new file mode 100644 index 0000000..2e1f100 --- /dev/null +++ b/Math/MathBug_01 @@ -0,0 +1,17 @@ +// https://www.interviewbit.com/problems/math_bug01/ + +// Return 1 if A is prime, else 0 +int Solution::isPrime(int A) { + int upperLimit = round(sqrt(A)); + if(A > 1){ + for (int i = 2; i <= upperLimit; i++) { + if (A % i == 0){ + return 0; + } + } + } + else{ + return 0; + } + return 1; +} From ef38b18307fc397566db3dbb13aa0ca3f179ba17 Mon Sep 17 00:00:00 2001 From: vaibhavsethia <40268761+vaibhavsethia@users.noreply.github.com> Date: Wed, 17 Oct 2018 18:42:09 +0530 Subject: [PATCH 2/4] Create MathBug_02 --- Math/MathBug_02 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Math/MathBug_02 diff --git a/Math/MathBug_02 b/Math/MathBug_02 new file mode 100644 index 0000000..898864a --- /dev/null +++ b/Math/MathBug_02 @@ -0,0 +1,16 @@ +// https://www.interviewbit.com/problems/math_bug02/ + +vector > Solution::squareSum(int A) { + vector > ans; + for (int a = 1; a * a < A; a++) { + for (int b = a; b * b <= A; b++) { + if (a * a + b * b == A) { + vector newEntry; + newEntry.push_back(a); + newEntry.push_back(b); + ans.push_back(newEntry); + } + } + } + return ans; +} From ac8d7272eebc9e8cc0cdf8e65be27475c4bd3f65 Mon Sep 17 00:00:00 2001 From: vaibhavsethia <40268761+vaibhavsethia@users.noreply.github.com> Date: Wed, 17 Oct 2018 18:42:26 +0530 Subject: [PATCH 3/4] Rename MathBug_01 to MathBug_01.cpp --- Math/{MathBug_01 => MathBug_01.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Math/{MathBug_01 => MathBug_01.cpp} (100%) diff --git a/Math/MathBug_01 b/Math/MathBug_01.cpp similarity index 100% rename from Math/MathBug_01 rename to Math/MathBug_01.cpp From a5ac11bc38d23717c4726a60e090dbeb89a50371 Mon Sep 17 00:00:00 2001 From: vaibhavsethia <40268761+vaibhavsethia@users.noreply.github.com> Date: Wed, 17 Oct 2018 18:42:52 +0530 Subject: [PATCH 4/4] Rename MathBug_02 to MathBug_02.cpp --- Math/{MathBug_02 => MathBug_02.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Math/{MathBug_02 => MathBug_02.cpp} (100%) diff --git a/Math/MathBug_02 b/Math/MathBug_02.cpp similarity index 100% rename from Math/MathBug_02 rename to Math/MathBug_02.cpp