Problem 45
- 投稿者 : rei
Original
Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:
Triangle Tn=n(n+1)/2 1, 3, 6, 10, 15, … Pentagonal Pn=n(3n1)/2 1, 5, 12, 22, 35, … Hexagonal Hn=n(2n1) 1, 6, 15, 28, 45, … It can be verified that T285 = P165 = H143 = 40755.
Find the next triangle number that is also pentagonal and hexagonal.
和訳
三角数, 五角数, 六角数は以下のように生成される.
三角数 Tn=n(n+1)/2 1, 3, 6, 10, 15, … 五角数 Pn=n(3n1)/2 1, 5, 12, 22, 35, … 六角数 Hn=n(2n1) 1, 6, 15, 28, 45, … T285 = P165 = H143 = 40755であることが分かる.
次の三角数かつ五角数かつ六角数な数を求めよ.
当てにならないソースコード(C#)
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 | using System; namespace ProjectEuler { class Problem45 : Problem{ public Problem45() { Func<long, long> mkt = (n)=>n*(n+1)/2, mkp = (n)=>n*(3*n-1)/2, mkh = (n)=>n*(2*n-1); long tn = 1, pn = 1, hn = 1, t = 1, p = 1, h = 1, found = 0; for (hn = 1; ; hn++) { h = mkh(hn); while(p < h) p = mkp(++pn); while (t < p) t = mkt(++tn); if (h == p && p == t) { ++found; if (found == 3) { Console.WriteLine("> " + t); break; } } } } } } |
Problem 44 Index Problem 46

rei@sikios.com
コメントはまだありません。