Ȼ/12

Top / Ȼ / 12



ؿˡ: Ƶ

Υԥ塼ιδؿǤϡʬȤ˻ȤֺƵפȤˡȤ롥 ˤĤƳؤܤ

notes.png sum(n) := 1 + 2 + ... + n ȤؿƵȤäƤߤΤǡʲ㤫򤷤褦

ޤоݤȤʤؿʬȤƤӽФǡֿŪˡʤ sum ȡ(n Ȥ)Τ褦ˤǤ뤳Ȥޤ򤷤褦

sum.png

warning.png դ뼰Ǥ뱦դˡդƱ sum ؿо줷Ƥ뤳Ȥܤ٤



ƵΩĤˤ?

κƵְ̣ġפˤϰʲΥݥȤƤ뤳ȤɬפǤ롥褯ͤƤߤ褦

  1. դդ֤˱դ֤ ³ƤˤʤäƤ롥
  2. ִη֤ɬפ褦ˤʤäƤȡɬ n=1 ξã褦ˤʤäƤ롥


NG.png ִηֽ֤ʤԤä硤ץϱʱߤʤ! ɬǽŪ˴뤹褦դ褦

ơƵΰ̣Ϥ狼äȤơץѤˤϤɤ뤫ؤܤ ¤ϻȤϴñǡ֤ۤܤΤޤޡ׽񤱤ɤ 㤨Фξϥץ񤯤ȼΤ褦ʴˤʤ롥

  1. def sum(n)
  2.   if (n == 1) then
  3.       return 1
  4.     else
  5.       return sum(n-1) + n
  6.   end
  7. end



notes.png ơưΤ? ºݤ˻Ƥߤ褦 κƵȤäơsum(10) ʤɤΤˤʤ뤳ȤǧƤߤ褦



ƵΤʤˤ򤷤Ρ



ƵκϤĤΤΤǤ롥

OK.png Ƶϡ񤯤Ǥ褤.
׻ץषʤɤ.

褯ͤԻ׵ĤʤȤǤϤʤ֤ŬѤФĤɬ뤹ʤΤ顤ԥ塼ƤʤΤ 줬ºݤϤȤƤʤȤ¿Τʲ򤷤褦

桼åɤθ߽ˡ

Ĥ n, m (n >= m) κͤ褦 λŪ˼Ω(ΤʤͤĴ٤褦)

n m κ m (n mod m) κ

(mod ϡ;פȤ̣)


äơȤĤ n, m (n >= m) κؿ gcd(n,m) ˤĤƼΤ褦ʺƵΩġ
gcd.png

warning.png μƵξƤ뤳Ȥǧ褦.



򤽤Τޤޥץߥ󥰤ȰʲΤ褦ˤʤ롥(n >= m) ȤǰΤ˳μ¤ˤƤΤˤäȤɬפɤäƤ뤫ϲΥץɤ⤦

  1. def gcd(n,m)
  2.   # ǰΤᡤn >= m μ¤ˤƤ.
  3.   if (n < m) then
  4.     n,m = m,n
  5.   end
  6.  
  7.   # ȤϺƵμ̤.
  8.   if (n % m == 0) then
  9.       return m
  10.     else
  11.       return gcd(m, (n % m) )
  12.   end
  13.  
  14. end



notes.png Ǽºݤ㤨 120 45 κ 15 ޤ뤳Ȥǧ褦
warning.png κƵֻȤ鷺ˡ׺ץबɤ줯餤ݤʤΤˤʤ뤫褦.

ʤηв᤬褯ʬʤȤͤϡΤ褦вϤ褦˿դäץưƤߤɤ

  1. include Math
  2.  
  3. # ؿ
  4. def gcd(n,m)
  5.   # ǰΤᡤn >= m μ¤ˤƤ.
  6.   if (n < m) then
  7.     n,m = m,n
  8.   end
  9.  
  10.   #  оݤȤƤĤοȡ mod .
  11.   print(n," mod ",m, " = ",n % m,"\n")
  12.  
  13.   # ȤϺƵμ̤.
  14.   if (n % m == 0) then
  15.       # ׻λ
  16.       print("Finished. \n")
  17.       return m
  18.     else
  19.       return gcd(m, (n % m) )
  20.   end
  21. end
  22.  
  23. # ʲץ
  24. n = 1071
  25. m = 1029
  26.  
  27. # ؿȤäƷ׻ɽ
  28. print("gcd(",n,", ",m,") = ",gcd(n,m),"\n")



Ƶȥ롼Ȥδط

for while ʤɤΥ롼פǤϥ롼פäƤƤӥ롼פưưϼʬȤƤӽФƵܼŪˤƱ԰٤ ȤȤϡ롼׷׻ϺƵǽ񤭤ʤȤǤϤդޤΤϤ Ĥޤꡤ

롼׷׻ϺƵǽľȤ衤
Ƶϥ롼׷׻ǽľȤϤ

ȤȤˤʤ롥



notes.png (֤;͵Τ͸) 桼åɤθ߽ˡƵȤ鷺˥ץߥ󥰤Ƥߤ褦



Ƶȥ롼סɤä?

Ƶȥ롼׷׻ܼŪƱʤ顤ɤ֤٤Ȥ꤬ǤƤ롥 ˤĤƤϡĤλ롥

ޤץΤ狼䤹ˤ롥 桼åɤθ߽ˡʤɤϺƵ狼䤹򼨤򤹤褦ʥפη׻ϥ롼פ狼䤹 礭񤤤Ƥȡ

Ƶȥ롼פΤɤ餬狼䤹ˤ

ˡ׻®䥳ԥ塼ˤ٤ˤĤƤǤ뤬 ʬȤ򲿲ƤӽФȤ߾塤̵ȺƵ٤⤤ 礭񤤤Ƥȡ

(Ǥ)ƵˡʤΤ MP (MP = Machine Power)

Ȥʤ롥 ɡåȤǥåȤ⤢ΤǡƵȤ٤ɤϥХȤȤˤʤ롥



ž夲

  1. notes.png ؿ(factorial) n! ƵȤäƴؿȤƥץष褦
    ʲξߤ褦ˤ褦
    1. 0! = 1, 1! = 1 Ȥ롥
    2. ưѥ᡼ n (30餤)Ϳ졤0!, 1!, 2!,... n! ޤǤϤΤȤ롥
    3. ץϡƵѤƷ׻Ȥ롥

      Ūˤϡ㤨ХץΥե̾ factorial.rb Ȥȡ

      ruby -w factorial.rb 20



      ȤƼ¹Ԥȡ
       0! = 1
       1! = 1
       2! = 2
       3! = 6
       4! = 24
       5! = 120
       6! = 720
       7! = 5040
       8! = 40320
       9! = 362880
       10! = 3628800
       11! = 39916800
       12! = 479001600
       13! = 6227020800
       14! = 87178291200
       15! = 1307674368000
       16! = 20922789888000
       17! = 355687428096000
       18! = 6402373705728000
       19! = 121645100408832000
       20! = 2432902008176640000
      Ȥ̤Ǥ褦ˤȤȤˤʤ롥

  2. notes.png Fibonacci F_0, F_1, F_2, ... ׻ƽϤץƵǽ񤳤(Fibonacci ΤʤͤĴ٤褦) ʲξΤȤ롥
  1. F_0 = 0, F_1 = 1 Ȥ.
  2. ưѥ᡼ n (30餤)Ϳ졤F_0, F_1, F_2,... F_n ޤǤϤΤȤ롥
  3. ץϡƵѤƷ׻Ȥ롥

    Ūˤϡ㤨ХץΥե̾ fibonacci.rb Ȥȡ

    ruby -w fibonacci.rb 30



    ȤƼ¹Ԥȡ
      F_0 = 0
      F_1 = 1
      F_2 = 1
      F_3 = 2
      F_4 = 3
      F_5 = 5
      F_6 = 8
      F_7 = 13
      F_8 = 21
      F_9 = 34
      F_10 = 55
      F_11 = 89
      F_12 = 144
      F_13 = 233
      F_14 = 377
      F_15 = 610
      F_16 = 987
      F_17 = 1597
      F_18 = 2584
      F_19 = 4181
      F_20 = 6765
      F_21 = 10946
      F_22 = 17711
      F_23 = 28657
      F_24 = 46368
      F_25 = 75025
      F_26 = 121393
      F_27 = 196418
      F_28 = 317811
      F_29 = 514229
      F_30 = 832040
    Ȥ̤Ǥ褦ˤȤȤˤʤ롥

    warning.png (Ը) ƵǤʤּ¹®٤®ץץ񤤤Ƥߤ褦ɤФ褤.



ݡ

ʲβˤĤơ긭Ĵȹͻȼ¹Ԥ򤷡

ExpMath1-Report-12

Ȥ̾Ĥ e-mail ˤƶ˥ݡȤȤФ补ʤƼ

  1. °(ز)
  2. ֹ
  3. ǯ
  4. ̾

񤯤Τ˺ʤ褦.

warning.png ʬΥݡȺġ륻åȤ򵭺ܤ(󡤺ΥݡȤ⤽Υġ륻åȤȤäƺ뤳)

ݡȲ

  1. ½ǽФƤФƤΡʬβץȡη̤򼨤
  2. 1. Υץ־ܺ٤ˡײ⤻补

about Icons, ClipArts

For details, see JNorth_arrow-right-sm.png this.


źեե: filesum.png 69 [ܺ] filegcd.png 69 [ܺ]