summaryrefslogtreecommitdiff
path: root/Quantitative_Aptitude_for_Competitive_Examinations/Chapter2.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'Quantitative_Aptitude_for_Competitive_Examinations/Chapter2.ipynb')
-rwxr-xr-xQuantitative_Aptitude_for_Competitive_Examinations/Chapter2.ipynb786
1 files changed, 786 insertions, 0 deletions
diff --git a/Quantitative_Aptitude_for_Competitive_Examinations/Chapter2.ipynb b/Quantitative_Aptitude_for_Competitive_Examinations/Chapter2.ipynb
new file mode 100755
index 00000000..c0146fd8
--- /dev/null
+++ b/Quantitative_Aptitude_for_Competitive_Examinations/Chapter2.ipynb
@@ -0,0 +1,786 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# 2: HCF and LCM of numbers"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.1, Page number 2.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "greatest number that will exactly divide is 40\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=200;\n",
+ "b=320; #given two numbers\n",
+ "\n",
+ "#Calculation\n",
+ "n=gcd(a,b); #required number\n",
+ "\n",
+ "#Result\n",
+ "print \"greatest number that will exactly divide is\",n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.2, Page number 2.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "greatest number that will exactly divide is 12\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=148;\n",
+ "b=246;\n",
+ "c=623; #given three numbers\n",
+ "a1=4;\n",
+ "b1=6;\n",
+ "c1=11; #remainders left\n",
+ "\n",
+ "#Calculation\n",
+ "A=a-a1;\n",
+ "B=b-b1;\n",
+ "C=c-c1; #obtained three numbers\n",
+ "n=gcd(A,B); #GCD of A and B\n",
+ "rn=gcd(n,C); #GCD of all the 3 numbers\n",
+ "\n",
+ "#Result\n",
+ "print \"greatest number that will exactly divide is\",rn"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.3, Page number 2.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "required least number is 6621.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1=27;\n",
+ "n2=35;\n",
+ "n3=45;\n",
+ "n4=49; #given numbers\n",
+ "r=6; #remainder\n",
+ "\n",
+ "#Calculation\n",
+ "l1=n1*n2/gcd(n1,n2); #lcm of n1 and n2\n",
+ "l2=n3*n4/gcd(n3,n4); #lcm of n3 and n4\n",
+ "l=l1*l2/gcd(l1,l2); #lcm of the given 4 numbers\n",
+ "L=l+6; #required least number\n",
+ "\n",
+ "#Result\n",
+ "print \"required least number is\",L"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.4, Page number 2.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "required least number is 565.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=36;\n",
+ "b=48;\n",
+ "c=64; #given three numbers\n",
+ "a1=25;\n",
+ "b1=37;\n",
+ "c1=53; #remainders left\n",
+ "\n",
+ "#Calculation\n",
+ "A=a-a1;\n",
+ "B=b-b1;\n",
+ "C=c-c1; #obtained three numbers\n",
+ "l1=a*b/gcd(a,b); #lcm of a and b\n",
+ "l2=l1*c/gcd(l1,c); #lcm of the given 3 numbers\n",
+ "L=l2-A; #required least number\n",
+ "\n",
+ "#Result\n",
+ "print \"required least number is\",L"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.5, Page number 2.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "greatest possible length of scale is 30 cm\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=300;\n",
+ "b=510;\n",
+ "c=1290; #given three numbers(cm)\n",
+ "\n",
+ "#Calculation\n",
+ "n=gcd(a,b); #gcd of a and b\n",
+ "rn=gcd(n,c); #gcd of all the numbers\n",
+ "\n",
+ "#Result\n",
+ "print \"greatest possible length of scale is\",rn,\"cm\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.6, Page number 2.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "required least number when increased by change is 202.0\n",
+ "required least number when decreased by change is 218.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=15;\n",
+ "b=21;\n",
+ "c=30; #given three numbers\n",
+ "r=8; #change\n",
+ "\n",
+ "#Calculation\n",
+ "l1=a*b/gcd(a,b); #lcm of a and b\n",
+ "l2=l1*c/gcd(l1,c); #lcm of the given 3 numbers\n",
+ "L1=l2-r; #required least number when increased by change\n",
+ "L2=l2+r; #required least number when decreased by change\n",
+ "\n",
+ "#Result\n",
+ "print \"required least number when increased by change is\",L1\n",
+ "print \"required least number when decreased by change is\",L2"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.7, Page number 2.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "greatest 4 digit number divisible by given numbers is 9660.0\n",
+ "answer given in the book is wrong\n",
+ "smallest 4 digit number divisible by given numbers is 1260.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=9999; #greatest 4 digit number\n",
+ "n0=1000; #smallest 4 digit number\n",
+ "n1=12;\n",
+ "n2=15;\n",
+ "n3=20;\n",
+ "n4=35; #given four numbers\n",
+ "\n",
+ "#Calculation\n",
+ "l1=n1*n2/gcd(n1,n2); #lcm of n1 and n2\n",
+ "l2=n3*n4/gcd(n3,n4); #lcm of n3 and n4\n",
+ "l=l1*l2/gcd(l1,l2); #lcm of the given 4 numbers\n",
+ "a=n%l; \n",
+ "A=n-a; #greatest 4 digit number divisible by given numbers\n",
+ "b=n0%l;\n",
+ "B=n0+l-b; #smallest 4 digit number divisible by given numbers\n",
+ "\n",
+ "#Result\n",
+ "print \"greatest 4 digit number divisible by given numbers is\",A\n",
+ "print \"answer given in the book is wrong\"\n",
+ "print \"smallest 4 digit number divisible by given numbers is\",B"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.8, Page number 2.6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "all bells toll together after an interval of 504.0 seconds\n",
+ "number of times they toll together in 2 hours is 14 times\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1=6;\n",
+ "n2=7;\n",
+ "n3=8;\n",
+ "n4=9; #intervals(sec)\n",
+ "n=2; #number of hours\n",
+ "\n",
+ "#Calculation\n",
+ "l1=n1*n2/gcd(n1,n2); #lcm of n1 and n2\n",
+ "l2=n3*n4/gcd(n3,n4); #lcm of n3 and n4\n",
+ "l=l1*l2/gcd(l1,l2); #lcm of the given 4 numbers\n",
+ "t=n*60*60/l; #number of times they toll together\n",
+ "\n",
+ "print \"all bells toll together after an interval of\",l,\"seconds\"\n",
+ "print \"number of times they toll together in 2 hours is\",int(t),\"times\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.9, Page number 2.6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "greatest 4 digit number divisible by given numbers is 9831.0\n",
+ "answer given in the book is wrong\n",
+ "smallest 4 digit number divisible by given numbers is 1011.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=9999; #greatest 4 digit number\n",
+ "n0=1000; #smallest 4 digit number\n",
+ "n1=12;\n",
+ "n2=18;\n",
+ "n3=21;\n",
+ "n4=28; #given four numbers\n",
+ "r=3; #remainder\n",
+ "\n",
+ "#Calculation\n",
+ "l1=n1*n2/gcd(n1,n2); #lcm of n1 and n2\n",
+ "l2=n3*n4/gcd(n3,n4); #lcm of n3 and n4\n",
+ "l=l1*l2/gcd(l1,l2); #lcm of the given 4 numbers\n",
+ "a=n%l; \n",
+ "A=n-a+r; #greatest 4 digit number divisible by given numbers\n",
+ "b=n0%l;\n",
+ "B=n0+l-b+r; #smallest 4 digit number divisible by given numbers\n",
+ "\n",
+ "#Result\n",
+ "print \"greatest 4 digit number divisible by given numbers is\",A\n",
+ "print \"answer given in the book is wrong\"\n",
+ "print \"smallest 4 digit number divisible by given numbers is\",B"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.10, Page number 2.6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "required numbers are 221.0 and 293.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=6;\n",
+ "b=8;\n",
+ "c=9; #given three numbers\n",
+ "r=5; #remainder\n",
+ "\n",
+ "#Calculation\n",
+ "l1=a*b/gcd(a,b); #lcm of a and b\n",
+ "l2=l1*c/gcd(l1,c); #lcm of the given 3 numbers\n",
+ "n1=(l2*3)+r;\n",
+ "n2=(l2*4)+r; #required numbers \n",
+ "\n",
+ "#Result\n",
+ "print \"required numbers are\",n1,\"and\",n2"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.11, Page number 2.6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "number of Aluminium wire pieces is 15.0\n",
+ "number of Copper wire pieces is 8.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=960;\n",
+ "b=512; #length of wires(cm)\n",
+ "\n",
+ "#Calculation\n",
+ "hcf=gcd(a,b); #HCF of two lengths\n",
+ "n1=a/hcf; #number of Aluminium wire pieces\n",
+ "n2=b/hcf; #number of Copper wire pieces\n",
+ "\n",
+ "#Result\n",
+ "print \"number of Aluminium wire pieces is\",n1\n",
+ "print \"number of Copper wire pieces is\",n2"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.12, Page number 2.7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "the other number is 80.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "hcf=16; #HCF 0f two numbers \n",
+ "lcm=240; #LCM of two numbers\n",
+ "a=48; #one of the numbers\n",
+ "\n",
+ "#Calculation\n",
+ "b=hcf*lcm/a; #the other number\n",
+ "\n",
+ "#Result\n",
+ "print \"the other number is\",b"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.13, Page number 2.7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "number of students is 35\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=105; #number of oranges\n",
+ "b=175; #number of bananas\n",
+ "\n",
+ "#Calculation\n",
+ "hcf=gcd(a,b); #number of students\n",
+ "\n",
+ "#Result\n",
+ "print \"number of students is\",hcf"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.14, Page number 2.7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resultant HCF is 0.0011\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=11;\n",
+ "b=121;\n",
+ "c=1331; #given three numbers(cm)\n",
+ "\n",
+ "#Calculation\n",
+ "n=gcd(a,b); #gcd of a and b\n",
+ "rn=gcd(n,c); #gcd of all the numbers\n",
+ "\n",
+ "#Result\n",
+ "print \"resultant HCF is\",rn/10**4"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.15, Page number 2.7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resultant LCM is 594.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=22;\n",
+ "b=540;\n",
+ "c=108; #given three numbers\n",
+ "\n",
+ "#Calculation\n",
+ "l1=a*b/gcd(a,b); #lcm of a and b\n",
+ "l=l1*c/gcd(l1,c); #lcm of the given 3 numbers\n",
+ "\n",
+ "#Result\n",
+ "print \"resultant LCM is\",l/10"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.16, Page number 2.7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resultant HCF is 243 or 3 ** 5\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=3**5;\n",
+ "b=3**9;\n",
+ "c=3**14; #given three numbers(cm)\n",
+ "base=3;\n",
+ "i=[5, 9, 14] #indices\n",
+ "\n",
+ "#Calculation\n",
+ "n=gcd(a,b); #gcd of a and b\n",
+ "rn=gcd(n,c); #gcd of all the numbers\n",
+ "hcf=min(i);\n",
+ "\n",
+ "#Result\n",
+ "print \"resultant HCF is\",rn,\"or\",base,\"**\",hcf"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example number 2.17, Page number 2.7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resultant LCM is 4 ** 12\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "from fractions import gcd\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=4**5;\n",
+ "b=4**-81;\n",
+ "c=4**12;\n",
+ "d=4**7; #given three numbers(cm)\n",
+ "base=4;\n",
+ "i=[5, -81, 12, 7] #indices\n",
+ "\n",
+ "#Calculation\n",
+ "lcm=max(i); #resultant LCM\n",
+ "\n",
+ "#Result\n",
+ "print \"resultant LCM is\",base,\"**\",lcm"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}