CM 4.5 Iteration MrG 2011.1117

3657 days ago by calcpage123

nMax=10 n=1 print "number","\t","sum" while n<=nMax: print n,"\t",n*(n+1)/2 n+=1 
       
number 	sum
1 	1
2 	3
3 	6
4 	10
5 	15
6 	21
7 	28
8 	36
9 	45
10 	55
number 	sum
1 	1
2 	3
3 	6
4 	10
5 	15
6 	21
7 	28
8 	36
9 	45
10 	55
#1) nMax=10 s=0 i=1 print "number","\t","sum" while i<=nMax: s+=i print i,"\t",s i+=2 
       
number 	sum
1 	1
3 	4
5 	9
7 	16
9 	25
number 	sum
1 	1
3 	4
5 	9
7 	16
9 	25
#2) nMax=30 s=0 i=6 print "number","\t","sum" while i<=nMax: s+=i print i,"\t",s i+=6 
       
number 	sum
6 	6
12 	18
18 	36
24 	60
30 	90
number 	sum
6 	6
12 	18
18 	36
24 	60
30 	90
#3) nMax=20 f=1 i=1 print "number","\t","sum" while i<=nMax: f*=i print i,"\t",f i+=1 
       
number 	sum
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
number 	sum
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
#4) 3s2/s=2n+1, 3s2=(2n+1)s, 3s2=(n(n+1)(2n+1))/2, s2=(n(n+1)(2n+1))/6 nMax=10 s=0 s2=0 i=1 print "number","\t","sum","\t","sum2","\t","ratio" while i<=nMax: s+=i s2+=i^2 print i,"\t",s,"\t",s2,"\t",3*s2/s i+=1 
       
number 	sum 	sum2 	ratio
1 	1 	1 	3
2 	3 	5 	5
3 	6 	14 	7
4 	10 	30 	9
5 	15 	55 	11
6 	21 	91 	13
7 	28 	140 	15
8 	36 	204 	17
9 	45 	285 	19
10 	55 	385 	21
number 	sum 	sum2 	ratio
1 	1 	1 	3
2 	3 	5 	5
3 	6 	14 	7
4 	10 	30 	9
5 	15 	55 	11
6 	21 	91 	13
7 	28 	140 	15
8 	36 	204 	17
9 	45 	285 	19
10 	55 	385 	21
#6) def myPow(x,n): p=1 i=1 while i<=n: p*=x i+=1 return p myPow(3.1415926,10) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}93648.0315014496
\newcommand{\Bold}[1]{\mathbf{#1}}93648.0315014496
#7) def smallestDivisor(n): d=2 while n%d!=0: d+=1 return d smallestDivisor(15) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}3
\newcommand{\Bold}[1]{\mathbf{#1}}3
smallestDivisor(7) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}7
\newcommand{\Bold}[1]{\mathbf{#1}}7
#8) def sumOfDivisors(n): d=1 s=0 while d<n: if n%d==0: s+=d d+=1 return s sumOfDivisors(6) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}6
\newcommand{\Bold}[1]{\mathbf{#1}}6
for i in range(1000000): if i==sumOfDivisors(i): print i 
       
0
6
28
496
8128
0
6
28
496
8128
#9) def sumInvSqr(n): s=0 i=1 print "i\tsum\t\t\tsqrt(6*sum)" while i<=n: s+=1/i^2 print i,"\t",s.n(),"\t",sqrt(6*s).n() i+=1 sumInvSqr(100) 
       
i	sum			sqrt(6*sum)
1 	1.00000000000000 	2.44948974278318
2 	1.25000000000000 	2.73861278752583
3 	1.36111111111111 	2.85773803324704
4 	1.42361111111111 	2.92261298612503
5 	1.46361111111111 	2.96338770103857
6 	1.49138888888889 	2.99137649474842
7 	1.51179705215420 	3.01177394784621
8 	1.52742205215420 	3.02729785665784
9 	1.53976773116654 	3.03950758956105
10 	1.54976773116654 	3.04936163598207
11 	1.55803219397646 	3.05748150670756
12 	1.56497663842090 	3.06428781783393
13 	1.57089379818422 	3.07007537189322
14 	1.57599583900054 	3.07505691557136
15 	1.58044028344499 	3.07938982603209
16 	1.58434653344499 	3.08319302033945
17 	1.58780674105744 	3.08655802575371
18 	1.59089316081053 	3.08955643496978
19 	1.59366324391302 	3.09224505230070
20 	1.59616324391302 	3.09466952411370
21 	1.59843081760917 	3.09686694994393
22 	1.60049693331165 	3.09886779322221
23 	1.60238729247989 	3.10069730139518
24 	1.60412340359100 	3.10237657635981
25 	1.60572340359100 	3.10392339170058
26 	1.60720269353183 	3.10535282394625
27 	1.60857443564431 	3.10667774541646
28 	1.60984994584839 	3.10790921281339
29 	1.61103900649049 	3.10905677641032
30 	1.61215011760160 	3.11012872814126
31 	1.61319070032792 	3.11113230222817
32 	1.61416726282792 	3.11207383861109
33 	1.61508553647347 	3.11295891698571
34 	1.61595058837659 	3.11379246743573
35 	1.61676691490720 	3.11457886229313
36 	1.61753851984547 	3.11532199284004
37 	1.61826898003539 	3.11602533369232
38 	1.61896150081101 	3.11669199711265
39 	1.61961896300694 	3.11732477904398
40 	1.62024396300694 	3.11792619829938
41 	1.62083884700456 	3.11849853006657
42 	1.62140574042859 	3.11904383466657
43 	1.62194657331123 	3.11956398233269
44 	1.62246310223685 	3.12006067463777
45 	1.62295692939735 	3.12053546308708
46 	1.62342951918941 	3.12098976530466
47 	1.62388221271589 	3.12142487916902
48 	1.62431624049367 	3.12184199519482
49 	1.62473273362153 	3.12224220740947
50 	1.62513273362153 	3.12262652293373
51 	1.62551720113402 	3.12299587044302
52 	1.62588702361923 	3.12335110765911
53 	1.62624302219524 	3.12369302799930
54 	1.62658595772336 	3.12402236649166
55 	1.62691653623575 	3.12433980504915
56 	1.62723541378678 	3.12464597718216
57 	1.62754320079816 	3.12494147221816
58 	1.62784046595869 	3.12522683908738
59 	1.62812773973059 	3.12550258972594
60 	1.62840551750837 	3.12576920214052
61 	1.62867426246940 	3.12602712317350
62 	1.62893440815098 	3.12627677100187
63 	1.62918636078389 	3.12651853739960
64 	1.62943050140889 	3.12675278978900
65 	1.62966718779942 	3.12697987310384
66 	1.62989675621081 	3.12720011148389
67 	1.63011952297401 	3.12741380981859
68 	1.63033578594978 	3.12762125515522
69 	1.63054582585737 	3.12782271798518
70 	1.63074990749002 	3.12801845342065
71 	1.63094828082864 	3.12820870227225
72 	1.63114118206321 	3.12839369203738
73 	1.63132883453084 	3.12857363780766
74 	1.63151144957832 	3.12874874310321
75 	1.63168922735610 	3.12891920064047
76 	1.63186235755000 	3.12908519303966
77 	1.63203102005633 	3.12924689347740
78 	1.63219538560531 	3.12940446628937
79 	1.63235561633756 	3.12955806752733
80 	1.63251186633756 	3.12970784547462
81 	1.63266428212784 	3.12985394112362
82 	1.63281300312725 	3.12999648861839
83 	1.63295816207629 	3.13013561566552
84 	1.63309988543230 	3.13027144391566
85 	1.63323829373680 	3.13040408931831
86 	1.63337350195746 	3.13053366245194
87 	1.63350561980658 	3.13066026883140
88 	1.63363475203799 	3.13078400919449
89 	1.63376099872401 	3.13090497976928
90 	1.63388445551414 	3.13102327252367
91 	1.63400521387665 	3.13113897539856
92 	1.63412336132467 	3.13125217252587
93 	1.63423898162759 	3.13136294443259
94 	1.63435215500921 	3.13147136823176
95 	1.63446295833331 	3.13157751780151
96 	1.63457146527776 	3.13168146395296
97 	1.63467774649787 	3.13178327458769
98 	1.63478186977983 	3.13188301484570
99 	1.63488390018489 	3.13198074724436
100 	1.63498390018489 	3.13207653180911
i	sum			sqrt(6*sum)
1 	1.00000000000000 	2.44948974278318
2 	1.25000000000000 	2.73861278752583
3 	1.36111111111111 	2.85773803324704
4 	1.42361111111111 	2.92261298612503
5 	1.46361111111111 	2.96338770103857
6 	1.49138888888889 	2.99137649474842
7 	1.51179705215420 	3.01177394784621
8 	1.52742205215420 	3.02729785665784
9 	1.53976773116654 	3.03950758956105
10 	1.54976773116654 	3.04936163598207
11 	1.55803219397646 	3.05748150670756
12 	1.56497663842090 	3.06428781783393
13 	1.57089379818422 	3.07007537189322
14 	1.57599583900054 	3.07505691557136
15 	1.58044028344499 	3.07938982603209
16 	1.58434653344499 	3.08319302033945
17 	1.58780674105744 	3.08655802575371
18 	1.59089316081053 	3.08955643496978
19 	1.59366324391302 	3.09224505230070
20 	1.59616324391302 	3.09466952411370
21 	1.59843081760917 	3.09686694994393
22 	1.60049693331165 	3.09886779322221
23 	1.60238729247989 	3.10069730139518
24 	1.60412340359100 	3.10237657635981
25 	1.60572340359100 	3.10392339170058
26 	1.60720269353183 	3.10535282394625
27 	1.60857443564431 	3.10667774541646
28 	1.60984994584839 	3.10790921281339
29 	1.61103900649049 	3.10905677641032
30 	1.61215011760160 	3.11012872814126
31 	1.61319070032792 	3.11113230222817
32 	1.61416726282792 	3.11207383861109
33 	1.61508553647347 	3.11295891698571
34 	1.61595058837659 	3.11379246743573
35 	1.61676691490720 	3.11457886229313
36 	1.61753851984547 	3.11532199284004
37 	1.61826898003539 	3.11602533369232
38 	1.61896150081101 	3.11669199711265
39 	1.61961896300694 	3.11732477904398
40 	1.62024396300694 	3.11792619829938
41 	1.62083884700456 	3.11849853006657
42 	1.62140574042859 	3.11904383466657
43 	1.62194657331123 	3.11956398233269
44 	1.62246310223685 	3.12006067463777
45 	1.62295692939735 	3.12053546308708
46 	1.62342951918941 	3.12098976530466
47 	1.62388221271589 	3.12142487916902
48 	1.62431624049367 	3.12184199519482
49 	1.62473273362153 	3.12224220740947
50 	1.62513273362153 	3.12262652293373
51 	1.62551720113402 	3.12299587044302
52 	1.62588702361923 	3.12335110765911
53 	1.62624302219524 	3.12369302799930
54 	1.62658595772336 	3.12402236649166
55 	1.62691653623575 	3.12433980504915
56 	1.62723541378678 	3.12464597718216
57 	1.62754320079816 	3.12494147221816
58 	1.62784046595869 	3.12522683908738
59 	1.62812773973059 	3.12550258972594
60 	1.62840551750837 	3.12576920214052
61 	1.62867426246940 	3.12602712317350
62 	1.62893440815098 	3.12627677100187
63 	1.62918636078389 	3.12651853739960
64 	1.62943050140889 	3.12675278978900
65 	1.62966718779942 	3.12697987310384
66 	1.62989675621081 	3.12720011148389
67 	1.63011952297401 	3.12741380981859
68 	1.63033578594978 	3.12762125515522
69 	1.63054582585737 	3.12782271798518
70 	1.63074990749002 	3.12801845342065
71 	1.63094828082864 	3.12820870227225
72 	1.63114118206321 	3.12839369203738
73 	1.63132883453084 	3.12857363780766
74 	1.63151144957832 	3.12874874310321
75 	1.63168922735610 	3.12891920064047
76 	1.63186235755000 	3.12908519303966
77 	1.63203102005633 	3.12924689347740
78 	1.63219538560531 	3.12940446628937
79 	1.63235561633756 	3.12955806752733
80 	1.63251186633756 	3.12970784547462
81 	1.63266428212784 	3.12985394112362
82 	1.63281300312725 	3.12999648861839
83 	1.63295816207629 	3.13013561566552
84 	1.63309988543230 	3.13027144391566
85 	1.63323829373680 	3.13040408931831
86 	1.63337350195746 	3.13053366245194
87 	1.63350561980658 	3.13066026883140
88 	1.63363475203799 	3.13078400919449
89 	1.63376099872401 	3.13090497976928
90 	1.63388445551414 	3.13102327252367
91 	1.63400521387665 	3.13113897539856
92 	1.63412336132467 	3.13125217252587
93 	1.63423898162759 	3.13136294443259
94 	1.63435215500921 	3.13147136823176
95 	1.63446295833331 	3.13157751780151
96 	1.63457146527776 	3.13168146395296
97 	1.63467774649787 	3.13178327458769
98 	1.63478186977983 	3.13188301484570
99 	1.63488390018489 	3.13198074724436
100 	1.63498390018489 	3.13207653180911