-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1303 lines (840 loc) · 30.6 KB
/
index.html
File metadata and controls
1303 lines (840 loc) · 30.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>eBash</title>
<meta name="author" content="Lv Kaiyang(Kevin Lui)">
<meta name="description" content="Table of Contents 1 Straight Forward
2 Answer Straight Forward 3252415338 4522814285776524134075932718654 5056464347 997651972577716695334890134043 …">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="http://kingfighter.github.io//">
<link href="/favicon.png" rel="icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<script src="/javascripts/modernizr-2.0.js"></script>
<script src="/javascripts/ender.js"></script>
<script src="/javascripts/octopress.js" type="text/javascript"></script>
<!-- By Kevin Lui-->
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
<!--/*--><![CDATA[/*><!--*/
MathJax.Hub.Config({
// Only one of the two following lines, depending on user settings
// First allows browser-native MathML display, second forces HTML/CSS
// config: ["MMLorHTML.js"], jax: ["input/TeX"],
jax: ["input/TeX", "output/HTML-CSS"],
extensions: ["tex2jax.js","TeX/AMSmath.js","TeX/AMSsymbols.js",
"TeX/noUndefined.js"],
//By Kevin 2013/4/30 for Latex
TeX: {equationNumbers: {autoNumber: ["AMS"], useLabelIds: true}},
SVG: {linebreaks: {automatic: true}},
tex2jax: {
inlineMath: [ ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"], ["\\begin{displaymath}","\\end{displaymath}"] ],
skipTags: ["script","noscript","style","textarea","pre","code"],
ignoreClass: "tex2jax_ignore",
processEscapes: false,
processEnvironments: true,
preview: "TeX"
},
showProcessingMessages: true,
displayAlign: "center",
displayIndent: "2em",
"HTML-CSS": {
scale: 100,
availableFonts: ["STIX","TeX"],
preferredFont: "TeX",
webFont: "TeX",
imageFont: "TeX",
showMathMenu: true,
//By Kevin 2013/4/30 for Latex
linebreaks: {automatic: true},
},
MMLorHTML: {
prefer: {
MSIE: "MML",
Firefox: "MML",
Opera: "HTML",
other: "HTML"
}
}
});
/*]]>*///-->
</script>
<link href="/atom.xml" rel="alternate" title="eBash" type="application/atom+xml">
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-40492618-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body >
<header role="banner"><hgroup>
<h1><a href="/">eBash</a></h1>
<h2>It is not the mountain we conquer but ourselves</h2>
</hgroup>
</header>
<nav role="navigation"><ul class="subscription" data-subscription="rss">
<li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
</ul>
<form action="http://google.com/search" method="get">
<fieldset role="search">
<input type="hidden" name="q" value="site:kingfighter.github.io/" />
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
</fieldset>
</form>
<ul class="main-navigation">
<li><a href="/">Blog</a></li>
<li><a href="/blog/archives">Archives</a></li>
<li><a href="/life">Life</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
<div id="main">
<div id="content">
<div class="blog-index">
<article>
<header>
<h1 class="entry-title"><a href="/blog/2014/04/24/project-euler-simple/">Project Euler Without Descriptions</a></h1>
<p class="meta">
<time datetime="2014-04-24T15:22:00+08:00" pubdate data-updated="true">Apr 24<span>th</span>, 2014</time>
| <a href="/blog/2014/04/24/project-euler-simple/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"></p>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1 Straight Forward</a></li>
<li><a href="#sec-2">2 Answer</a></li>
</ul>
</div>
</div>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Straight Forward</h2>
<div class="outline-text-2" id="text-1">
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup><col class="right" /></colgroup>
<colgroup><col class="right" /></colgroup><colgroup><col class="right" /></colgroup><colgroup><col class="right" /></colgroup><colgroup><col class="right" /></colgroup>
<thead>
</thead>
<tbody>
<tr><td class="right">32</td><td class="right">52</td><td class="right">41</td><td class="right">53</td><td class="right">38</td></tr>
</tbody>
<tbody>
<tr><td class="right">45228</td><td class="right">142857</td><td class="right">7652413</td><td class="right">4075</td><td class="right">932718654</td></tr>
</tbody>
<tbody>
<tr><td class="right">50</td><td class="right">56</td><td class="right">46</td><td class="right">43</td><td class="right">47</td></tr>
</tbody>
<tbody>
<tr><td class="right">997651</td><td class="right">972</td><td class="right">5777</td><td class="right">16695334890</td><td class="right">134043</td></tr>
</tbody>
<tbody>
<tr><td class="right">49</td><td class="right">55</td><td class="right">44</td><td class="right">97</td><td class="right"></td></tr>
</tbody>
<tbody>
<tr><td class="right">296962999629</td><td class="right">249</td><td class="right">5482660</td><td class="right">8739992577</td><td class="right"></td></tr>
</tbody>
</table>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Answer</h2>
<div class="outline-text-2" id="text-2">
<p>Source:<a href="https://github.com/kingFighter/project-euler">project-euler</a>
</p></div>
</div>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2014/04/10/project-euler-33/">Project Euler Problem 33</a></h1>
<p class="meta">
<time datetime="2014-04-10T22:38:00+08:00" pubdate data-updated="true">Apr 10<span>th</span>, 2014</time>
| <a href="/blog/2014/04/10/project-euler-33/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"></p>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1 Problem</a></li>
<li><a href="#sec-2">2 Solution</a></li>
<li><a href="#sec-3">3 Answer</a></li>
</ul>
</div>
</div>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Problem</h2>
<div class="outline-text-2" id="text-1">
<blockquote>
<p>The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s.
</p>
<p>
We shall consider fractions like, 30/50 = 3/5, to be trivial examples.
</p>
<p>
There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in the numerator and denominator.
</p>
<p>
If the product of these four fractions is given in its lowest common terms, find the value of the denominator.
</p>
</blockquote>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Solution</h2>
<div class="outline-text-2" id="text-2">
<p>很简单,解空间很小,可直接Brute Force.
</p>
<p>
但我们可以进一步缩小解空间.其可能的四种形式:
</p><ol>
<li>\begin{eqnarray*}
\frac{10a+b}{10c+b} = \frac{a}{c}
\end{eqnarray*}
</li>
<li>\begin{eqnarray*}
\frac{10a+b}{10b+c} = \frac{a}{c}
\end{eqnarray*}
</li>
<li>\begin{eqnarray*}
\frac{10b+a}{10c+b} = \frac{a}{c}
\end{eqnarray*}
</li>
<li>\begin{eqnarray*}
\frac{10b+a}{10b+c} = \frac{a}{c}
\end{eqnarray*}
</li>
</ol>
<p>
对于1,4 化简得出a=c,与条件矛盾
</p>
<p>
对于3,可利用a,b,c <=9 及a<b可得到矛盾
</p>
<p>
对此只有2才是可能的形式
</p></div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">Answer</h2>
<div class="outline-text-2" id="text-3">
<p>100
</p>
<p>
Source:<a href="https://github.com/kingFighter/project-euler">project-euler</a>
</p></div>
</div>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2014/04/05/project-euler-39/">Project Euler Problem 39</a></h1>
<p class="meta">
<time datetime="2014-04-05T00:09:00+08:00" pubdate data-updated="true">Apr 5<span>th</span>, 2014</time>
| <a href="/blog/2014/04/05/project-euler-39/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"></p>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1 Problem</a></li>
<li><a href="#sec-2">2 Solution</a></li>
<li><a href="#sec-3">3 Answer</a></li>
</ul>
</div>
</div>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Problem</h2>
<div class="outline-text-2" id="text-1">
<blockquote>
<p>If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
</p>
<p>
{20,48,52}, {24,45,51}, {30,40,50}
</p>
<p>
For which value of p ≤ 1000, is the number of solutions maximised?
</p>
</blockquote>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Solution</h2>
<div class="outline-text-2" id="text-2">
<p>简单,Brute Force.
</p></div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">Answer</h2>
<div class="outline-text-2" id="text-3">
<p>840
</p>
<p>
Source:<a href="https://github.com/kingFighter/project-euler">project-euler</a>
</p></div>
</div>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2014/04/04/project-euler-45/">Project Euler Problem 45</a></h1>
<p class="meta">
<time datetime="2014-04-04T23:28:00+08:00" pubdate data-updated="true">Apr 4<span>th</span>, 2014</time>
| <a href="/blog/2014/04/04/project-euler-45/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"></p>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1 Problem</a></li>
<li><a href="#sec-2">2 Solution</a></li>
<li><a href="#sec-3">3 Answer</a></li>
</ul>
</div>
</div>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Problem</h2>
<div class="outline-text-2" id="text-1">
<blockquote>
<p>Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:
</p>
<p>
Triangle Tn=n(n+1)/2 1, 3, 6, 10, 15, …
Pentagonal Pn=n(3n−1)/2 1, 5, 12, 22, 35, …
Hexagonal Hn=n(2n−1) 1, 6, 15, 28, 45, …
It can be verified that T285 = P165 = H143 = 40755.
</p>
<p>
Find the next triangle number that is also pentagonal and hexagonal.
</p>
</blockquote>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Solution</h2>
<div class="outline-text-2" id="text-2">
<p>简单,一元二次方程组.
</p></div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">Answer</h2>
<div class="outline-text-2" id="text-3">
<p>1533776805
</p>
<p>
Source:<a href="https://github.com/kingFighter/project-euler">project-euler</a>
</p></div>
</div>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2014/03/14/project-euler-42/">Project Euler Problem 42</a></h1>
<p class="meta">
<time datetime="2014-03-14T21:11:00+08:00" pubdate data-updated="true">Mar 14<span>th</span>, 2014</time>
| <a href="/blog/2014/03/14/project-euler-42/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"></p>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1 Problem</a></li>
<li><a href="#sec-2">2 Solution</a></li>
<li><a href="#sec-3">3 Answer</a></li>
</ul>
</div>
</div>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Problem</h2>
<div class="outline-text-2" id="text-1">
<blockquote>
<p>The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangle numbers are:
</p>
<p>
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, …
</p>
<p>
By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value is a triangle number then we shall call the word a triangle word.
</p>
<p>
Using <a href="https://projecteuler.net/project/words.txt">words.txt</a> (right click and ‘Save Link/Target As…’), a 16K text file containing nearly two-thousand common English words, how many are triangle words?
</p>
</blockquote>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Solution</h2>
<div class="outline-text-2" id="text-2">
<p>太简单
</p></div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">Answer</h2>
<div class="outline-text-2" id="text-3">
<p>162
</p>
<p>
Source:<a href="https://github.com/kingFighter/project-euler">project-euler</a>
</p></div>
</div>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2014/03/03/project-euler-31/">Project Euler Problem 31</a></h1>
<p class="meta">
<time datetime="2014-03-03T20:45:00+08:00" pubdate data-updated="true">Mar 3<span>rd</span>, 2014</time>
| <a href="/blog/2014/03/03/project-euler-31/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"></p>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1 Problem</a></li>
<li><a href="#sec-2">2 Solution</a>
<ul>
<li><a href="#sec-2-1">2.1 Brute Force</a></li>
<li><a href="#sec-2-2">2.2 Recursion</a></li>
<li><a href="#sec-2-3">2.3 DP</a></li>
</ul>
</li>
<li><a href="#sec-3">3 Answer</a></li>
</ul>
</div>
</div>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Problem</h2>
<div class="outline-text-2" id="text-1">
<blockquote>
<p>In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:
</p>
<p>
1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
</p>
<p>
It is possible to make £2 in the following way:
</p>
<p>
1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
</p>
<p>
How many different ways can £2 be made using any number of coins?
</p>
</blockquote>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Solution</h2>
<div class="outline-text-2" id="text-2">
</div>
<div id="outline-container-2-1" class="outline-3">
<h3 id="sec-2-1">Brute Force</h3>
<div class="outline-text-3" id="text-2-1">
<p>可以用穷举法:
</p>
<p>
200a+100b+50c+20d+10e+5f+2g+h = 200
</p>
<p>
穷尽a,b,c,d,e,f,g,h所有的可能.a:0~1, b:0~2…., 不过知道a = 1时, b:0,
可缩小a,b,c….大小范围, 见 C++Brute1, 类似的见C++Brute2
</p></div>
</div>
<div id="outline-container-2-2" class="outline-3">
<h3 id="sec-2-2">Recursion</h3>
<div class="outline-text-3" id="text-2-2">
<p>很直接的方法:
</p><ol>
<li>用一个200的coin, 没用其它的
</li>
<li>用零个200的coin, 由最大coin为100的来换零钱200
</li>
<li>用两个100的coin, 没用其它的
</li>
<li>用一个100的coin, 由最大coin为50的来换零钱100
</li>
<li>用零个100的coin, 由最大coin为50的来换零钱200
</li>
</ol>
<p> …..
</p>
<p>
这里大家应该能看出规律, 用公式表示:
</p>
<p>
\begin{eqnarray*}
f(t, c) = 1 & & if & c =1 &or& t=0 & \newline
f(t,c) = \sum_{i=0}^{\left \lfloor \frac{t}{c} \right \rfloor}f(t-ic, s(c)) & & if & c > 1 & and & t>0 &
\end{eqnarray*}
其中t是要换的钱, c是当前最大的coin,s(c)是下一个比c小的coin
</p>
<p>
见 C++Formula, 稍有不同的解法见 C++Formula1
</p>
</div>
</div>
<div id="outline-container-2-3" class="outline-3">
<h3 id="sec-2-3">DP</h3>
<div class="outline-text-3" id="text-2-3">
<p>见<a href="http://www.mathblog.dk/project-euler-31-combinations-english-currency-denominations/">分析</a>
</p></div>
</div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">Answer</h2>
<div class="outline-text-2" id="text-3">
<p>73682
</p>
<p>
Source:<a href="http://1drv.ms/Nn1zWO">C++Formula</a>, <a href="http://1drv.ms/1eVztrC">C++Formula1,</a> <a href="http://1drv.ms/1cnATAU">C++Brute1</a>, <a href="http://1drv.ms/1gMSteo">C++Brute2</a>, <a href="http://1drv.ms/1eVzMCU">dp</a>
</p></div>
</div>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2014/03/02/project-euler-26/">Project Euler Problem 26</a></h1>
<p class="meta">
<time datetime="2014-03-02T14:13:00+08:00" pubdate data-updated="true">Mar 2<span>nd</span>, 2014</time>
| <a href="/blog/2014/03/02/project-euler-26/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"></p>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1 Problem</a></li>
<li><a href="#sec-2">2 Solution</a></li>
<li><a href="#sec-3">3 Answer</a></li>
</ul>
</div>
</div>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Problem</h2>
<div class="outline-text-2" id="text-1">
<blockquote>
<p>
A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given:
</p>
<p>
1/2 = 0.5
</p>
<p>
1/3 = 0.(3)
</p>
<p>
1/4 = 0.25
</p>
<p>
1/5 = 0.2
</p>
<p>
1/6 = 0.1(6)
</p>
<p>
1/7 = 0.(142857)
</p>
<p>
1/8 = 0.125
</p>
<p>
1/9 = 0.(1)
</p>
<p>
1/10 = 0.1
</p>
<p>
Where 0.1(6) means 0.166666…, and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle.
</p>
<p>
Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
</p>
</blockquote>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Solution</h2>
<div class="outline-text-2" id="text-2">
<p> Brute Force,将小数部分保存vector中, 然后从头遍历寻找是否有相同的
pattern, 重复找到三次即认可.
</p>
<p>
更优的做法需要数学知识<sup><a class="footref" name="fnr-.1" href="#fn-.1">1</a></sup>
</p></div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">Answer</h2>
<div class="outline-text-2" id="text-3">
<p>983
</p>
<p>
Source:<a href="http://1drv.ms/1eOxC7U">C++</a>
</p>
<div id="footnotes">
<h2 class="footnotes">Footnotes: </h2>
<div id="text-footnotes">
<p class="footnote"><sup><a class="footnum" name="fn-.1" href="#fnr-.1">1</a></sup> <a href="http://mathworld.wolfram.com/DecimalExpansion.html">http://mathworld.wolfram.com/DecimalExpansion.html</a>
</p>
</div>
</div>
</div>
</div>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2013/08/28/project-euler-40/">Project Euler Problem 40</a></h1>
<p class="meta">
<time datetime="2013-08-28T21:51:00+08:00" pubdate data-updated="true">Aug 28<span>th</span>, 2013</time>
| <a href="/blog/2013/08/28/project-euler-40/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"></p>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1 Problem</a></li>
<li><a href="#sec-2">2 Solution</a></li>
<li><a href="#sec-3">3 Answer</a></li>
</ul>
</div>
</div>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1"><span class="section-number-2">1</span> Problem</h2>
<div class="outline-text-2" id="text-1">
<blockquote>
<p>An irrational decimal fraction is created by concatenating the positive integers:
</p>
<p>
0.123456789101112131415161718192021…
</p>
<p>
It can be seen that the \(12^{th}\) digit of the fractional part is 1.
</p>
<p>
If dn represents the nth digit of the fractional part, find the value of the following expression.
</p>
\begin{eqnarray*}
d_{1} × d_{10} × d_{100} × d_{1000} × d_{10000} × d_{100000} × d_{1000000}
\end{eqnarray*}
</blockquote>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2"><span class="section-number-2">2</span> Solution</h2>
<div class="outline-text-2" id="text-2">
<p>二分法,我们无法直接得知第ith的digit,但是容易知道number n所在的位置.要找ith的digit,其必夹在1~i number之间的某个位置.如:
</p>
<p>
找1000th的digit
</p><ol>
<li>其必夹在1~1000 number之间,易知 (1 + 1000) / 2 = 500 的最后一位0在序列中的位置为1392th(number 11的最后一位1的位置为13),比1000th大,则必在1~499间
</li>
<li>如此往复,我们可以找到最接近的number 370,其最后一位0为1002th,则1000th为digit 3
</li>
</ol>