[ab initio math] 174th Section algorithm preliminary

Source: Internet
Author: User
Tags gcd pow

plot summary:
[Machine Xiao Wei], accompanied by [engineer Ah Wei], entered the middle of the end of Dan's cultivation,
The goal of this time to practice is [algorithm preliminary].

Drama Start:

Star Calendar April 12, 2016 08:54:58, the Milky Way Galaxy Earles the Chinese Empire Jiangnan Line province.
[Engineer Ah Wei] is working with [machine Xiao Wei] to study [algorithm Preliminary].


[People challenged the teacher] pointing small Wei said: "This elixir to big, smooth into the yuan baby period, it must be nine turn to culture."
What is this nine-turn-to-the-Dharma? is to first rapid cultivation [heaven and earth people formal list] into the late, do not control all kinds of minor repairs
Work method, and then travel from beginning to end [heaven and earth People], in the journey of growth, refining the avatar, and finally re-cultivation [surgery, flow,
and Static] These methods of the auxiliary work method. In this way, nature can achieve elixir achievements, the Avatar invincible. “


[People challenge teacher] and said: "Now this repair celestial, all denominations, all widely received disciple janitor, teaching practice. But
Is these denominations, is nothing more than the use of poke trial, this three days a touch bone, five days a body, walking is the side of the door-keeper pass.
These joined the various factions of the monks, but also covet the magic of the various portals of the method, the East learning a recruit, the west to practice a style, the end of learning barge
Impurity is not pure, rare true line. The so-called inefficient person also. “


Xiao Wei said: "The teacher said, students will not know, students will naturally only learn the law of the teacher." All the other factions.
, even if the work of the law to say thousands of good million good, the hype, the flood of Golden Spring, students will not listen to. “


[People challenged the teacher] to Xiao Wei's answer is very satisfied, said: "If so, so-called poke boundless, rebuild. Another question
The sea is boundless, not crossing is the master. You will be able to take my work of the countries of the country, the nature is true line in hand, the world I
Yes. ”


So the two men Sanda.








<span style= "FONT-SIZE:18PX;" >import math;def tmp (n):    if Prime (n):        print (n, ' is prime number. ');    else:        print (N, ' is not a prime number. #判断一个数是否质数def Prime (num):    if (num < 2):        return False;        SQR = Int (math.sqrt (num)) +1;    For I in range (2, SQR):        if (num%i==0):            return False;    return true;if __name__ = = ' __main__ ':    tmp (7);    TMP (;</span>)


>>>
7 are prime numbers.
35 are not prime numbers.


Generally, know a number is not prime, always want to break down factorization look,

You can do this:

<span style= "FONT-SIZE:18PX;" > #分解质因数def primefactor (num, lists):    if (num < 2):        lists.append (num);        return lists;    Elif (prime (num) = = True):        lists.append (num);        return lists;    else:            sqr = int (math.sqrt (num)) +1;        i = 2;        While I <= SQR:            if (num% i = = 0 and prime (i) = = True):                lists.append (i);                num = num//i;                break;                        I+=1;        return Primefactor (num, lists);       </span>


>>>
7 are prime numbers.
35 are not prime numbers.
123456123457 are not prime numbers.
[5, 7]
[7]
[1039, 2528129]


<span style= "FONT-SIZE:18PX;" >    tmp (7);    TMP (+);    TMP (123456123457);    Print (Primefactor (+ []));    Print (Primefactor (7, []));    Print (Primefactor (123456123457, []));</span>


<span style= "FONT-SIZE:18PX;"                >if (1) {var r = 20;                  Config.setsector (1,1,1,1);                Config.graphpaper2d (0, 0, R);                              Config.axis2d (0, 0,180, 1);              Axis set var ScaleX = 2*r, ScaleY = 2*r;               var SpaceX = 2, SpaceY = 2;              var XS = -10, XE = 10;              var YS = -10, YE = 10;                Config.axisspacing (XS, XE, SpaceX, ScaleX, ' X ');                                Config.axisspacing (YS, YE, SpaceY, ScaleY, ' Y ');                var transform = new transform ();                         Store the points on the function image var a = [];        The function that needs to be shown shows var f1 = ' y=x*x-2 '; function Stroke for (var x = XS; x <= XE; x+=0.3) {if (x! = 0) {A.push ([x, Funt                        Ask (x)]);          }}//Two to find the minimum and maximum value of the function's 0 points//interval var MinX = 0, MaxX = 4;          var y1 = y2 = 0; x = miNX;          Y1 = Funtask (x);          x = MaxX;                    y2 = funtask (x);              If there are 0 points on the given interval (y1 * y2 < 0) {var epsilon = 0.000001;                  while (Math.Abs (y1-y2) > Epsilon) {x = MinX;                  Y1 = Funtask (x);                  x = MaxX;                                                      y2 = funtask (x);                  x = (Minx+maxx)/2;                                    y = funtask (x);                  if (Y * Y1 < 0) {MaxX = x;                  } else {MinX = x; }} plot.setfillstyle (' Blue '). Filltext (' 0 points: x = ' + ((minx+m          AxX)/2). ToFixed (3),-200,-60, 120);                          }//Store temporary array var tmp = []; Show transform if (A.length > 0) {a = Transform.scale (Transform.translate (A, 0, 0), SCalex/spacex, Scaley/spacey);                    function 1 TMP = [].concat (a);                    Shape.pointdraw (TMP, ' red ');                    TMP = [].concat (a);                                    Shape.multilinedraw (tmp, ' Pink ');                Plot.setfillstyle (' Red ');              Plot.filltext (F1, 100,-90, 200); }}</span>


<span style= "FONT-SIZE:18PX;" >function Funtask (x) {      return x*x-2;  }  </span>









Now, Xiao Wei has two ways to know the area of a triangle,

The first of these is:

<span style= "FONT-SIZE:18PX;" >if (1) {var r =;            Config.setsector (1,1,1,1);              Config.graphpaper2d (0, 0, R);            Config.axis2d (0, 0, in);  var scale = 2*r;//Triangle's three-side length var a = 3, B = 4, c = 5;var triangle = new triangle (); var transform = new transform (); var array = Triangle.know3edges ([A, B, c]); Shape.angledraw (Transform.translate (array, -200/scale, 0), ' cyan ', scale);          Shape.areadraw (array, ' red ', scale);  } </span>



The second type is:


>>>
The area of the triangle is: 6.0


<span style= "FONT-SIZE:18PX;" > #海伦-Qin Jiushao formula Def hqformula (A, B, c):    p = (a+b+c)/2;    S = Math.sqrt (p* (p-a) * (p-b) * (p-c));    return S;  if __name__ = = ' __main__ ':    print (' The area of the triangle is: ', Hqformula (3, 4, 5));</span>



<span style= "FONT-SIZE:18PX;" >>>>-5, 100-4, 110-3, 102-2, 82-1, 560, 301--102  465-110def Poly (x):    return ((x+3) *x-24) *x+30;if __name__ = = ' __main__ '    : for x in range ( -5, 6):        print (x, ' and ', poly (x));</span>

Xiao Wei wants to see what kind of a function this is:

<span style= "FONT-SIZE:18PX;"                >if (1) {var r = 20;                  Config.setsector (1,1,1,1);                Config.graphpaper2d (0, 0, R);                              Config.axis2d (0, 0,180);              Axis set var ScaleX = 2*r, ScaleY = 2*r;               var SpaceX = 2, SpaceY = 50;              var XS = -10, XE = 10;              var YS = -100, YE = 200;                Config.axisspacing (XS, XE, SpaceX, ScaleX, ' X ');                                Config.axisspacing (YS, YE, SpaceY, ScaleY, ' Y ');                var transform = new transform ();                         Store the points on the function image var a = [];        The function that needs to be shown shows var f1 = ' y=x^3+3x^2-24x+30 '; function Stroke for (var x = XS; x <= XE; x+=0.3) {if (x! = 0) {A.push ([x, Funt                        Ask (x)]);          }}//Two to find the minimum and maximum value of the function's 0 points//interval var MinX = 0, MaxX = 4;      var y1 = y2 = 0;    x = MinX;          Y1 = Funtask (x);          x = MaxX;                    y2 = funtask (x);              If there are 0 points on the given interval (y1 * y2 < 0) {var epsilon = 0.000001;                  while (Math.Abs (y1-y2) > Epsilon) {x = MinX;                  Y1 = Funtask (x);                  x = MaxX;                                                      y2 = funtask (x);                  x = (Minx+maxx)/2;                                    y = funtask (x);                  if (Y * Y1 < 0) {MaxX = x;                  } else {MinX = x; }} plot.setfillstyle (' Blue '). Filltext (' 0 points: x = ' + ((minx+m          AxX)/2). ToFixed (3),-200,-60, 120);                          }//Store temporary array var tmp = []; Show transform if (A.length > 0) {a = Transform.scale (Transform.translate (A, 0, 0), Scalex/spacex, Scaley/spacey);                    function 1 TMP = [].concat (a);                    Shape.pointdraw (TMP, ' red ');                    TMP = [].concat (a);                                    Shape.multilinedraw (tmp, ' Pink ');                Plot.setfillstyle (' Red ');              Plot.filltext (F1, 100,-90, 200);  }}function Funtask (x) {return Math.pow (x, 3) +3*math.pow (x, 2) -24*x+30; } </span>








<span style= "FONT-SIZE:18PX;"  >>>> Step 1:  8251 6105step 2:  6105 2146step 3:  2146 1813step 4:  1813 333step 5:  333 148step 6:  148 3737def gcd (M, N):    m, n = max (M, N), Min (m, n);    i = 1;    While N:        print (' Step ', I, ': ', M, n);        i + = 1;        m, n = n, m% n            return mif __name__ = = ' __main__ ':    print (GCD (8251, 6105));</span>







>>>
Step 1:98 63
Step 2:63 35
Step 3:35 28
Step 4:28 7
7




<span style= "FONT-SIZE:18PX;" > #秦九韶公式计算多项式的值def poly (x, Coef):    #coef为多项式按次数从高到低排列的系数矩阵    rank = len (COEF);    result = 0;    For I in range (rank):        result *= x;        Result + = Coef[i];    return result;if __name__ = = ' __main__ ':    print (poly (5, [1,1,1,1,1,1]));</span>


>>>
3906



<span style= "FONT-SIZE:18PX;" >>>> 14130.2# Qin Jiushao formula calculates the value of the polynomial Def poly (x, Coef):    #coef为多项式按次数从高到低排列的系数矩阵    rank = len (COEF);    result = 0;    For I in range (rank):        result *= x;        Result + = Coef[i];    return result;if __name__ = = ' __main__ ':    print (poly (5, [4,2,3.5,-2.6,1.7,-0.8]));</span>


<span style= "FONT-SIZE:18PX;" >>>> 0.0014992598466277984if __name__ = = ' __main__ ':    print (poly (0.477, [4,2,3.5,-2.6,1.7,-0.8])); </span>


<span style= "FONT-SIZE:18PX;" >>>>- 0.21984000000000004-0.1959787996000001-0.17082158719999996-0.14428610279999987-0.11628759039999992-0.08673874999999975-0.0 5554968959999984-0.0226278771999998130.012121907200000170.048797619600000286if __name__ = = ' __main__ ':    x = 0.4;    while (x < 0.5):        print (poly (x, [4,2,3.5,-2.6,1.7,-0.8]));        x + = 0.01;</span>






<span style= "FONT-SIZE:18PX;" >>>> 1011001def Dec2bin (N):    s = ';    a = [];        A.append (n%2);    n//=2;    While N > 0:        a.append (n%2);        n//=2;    size = Len (a);    For I in range (size):        s + = str (a[size-i-1]);    return s;if __name__ = = ' __main__ ':    N =--;    Print (n, '--', Dec2bin (n));</span>



<span Style= "FONT-SIZE:18PX;" >>>> 101100189---13189-59>>> ================================ RESTART ======= =========================>>>---100000000001024---20001024-400>>> ============= =================== RESTART ================================>>> 255-to-11111111255-377255-    Ffdef dec2k (N, k): s = ';    a = [];        #只提供了36进制数以内的唯一表示对照表 if k > 36:return ';    chartable = ' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ ';    A.append (N%K);    N//=k;        While N > 0:a.append (n%k);    N//=k;    size = Len (a);    For I in range (size): s + = chartable[a[size-i-1]];    return s;    if __name__ = = ' __main__ ': N = 255;    Print (n, '---', DEC2K (n, 2));    Print (n, '---', DEC2K (n, 8)); Print (n, '---', dec2k (n, +)); </span> 

[People challenge teacher] here the reason is to limit K within 10, is worried about the number is not enough,

But Xiao Wei also has the letter to join, do not worry about this problem,

So it can be expanded up to 36 binary.

<span style= "FONT-SIZE:18PX;" >>>> 108--1101100108--154108--6c108
<span style= "FONT-SIZE:18PX;" >    print (N, '-and ', DEC2K (n, +));    Print (n, '--', DEC2K (n, $));</span>

Liangshan 108 will, in the 36 binary is just three square.



<span style= "FONT-SIZE:18PX;" >if __name__ = = ' __main__ ':    #1    task = [[225,135],[98,196],[72,168],[153,119]];    For I in range (Len (Task)):        print (GCD (task[i][0], task[i][1]));    #2    Print (poly (5, [0.83,0.41,0.16,0.33,0.5,1]));    #3    N = +;    Print (n, '---', DEC2K (n, 2));    Print (n, '---', DEC2K (n, 8));    Print (n, '---', dec2k (n, +));    Print (n, '---', dec2k (n, +));    Print (n, '--', dec2k (n, i));>>> Step 1:  225 135step 2:  135 90step 3:  4545step 1:  196 9898step 1:  168 72step 2:  2424step 1:  153 119step 2:  119 34step 3:  34 17172881.749999 9999992008--111110110002008---37302008, 7d82008---1uo2008



<span style= "FONT-SIZE:18PX;" >function Funtask (x) {      return 0.83*math.pow (x, 5) +0.41*math.pow (x,4) +0.16*math.pow (x, 3) +0.33*math.pow (x, 2) + 0.5*x+1;  }  </span>





The end of this section, to know how to funeral, please see tell.



[ab initio math] 174th Section algorithm preliminary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.