2013-09-01から1ヶ月間の記事一覧

Project Euler 5

PE

Problem 5 and と i のいずれでも割り切れる数は不要なので gcd で取り除く。lcm で求める方法もある。 using System; namespace PE { public class PE005 { public static void Calc() { int ans = 1; for (int i = 1; i <= 20; i++) { ans = ans / Util.Gc…

Project Euler 4

PE

Problem 4 using System; namespace PE { public class PE004 { public static bool IsPalindrome(int n) { string s = n.ToString(); for (int i = 0; i < s.Length/2; i++) { if (s[i] != s[s.Length - i - 1]) { return false; } } return true; } public…

Project Euler 3

PE

Problem 3 using System; using System.Collections.Generic; namespace PE { public class PE003 { public static void Calc() { long n = 600851475143; List<long> factors = new List<long>(); long x = 3; while (x*x <= n) { if (n % x == 0) { factors.Add(x); n </long></long>…

Project Euler 2

PE

Problem 2 using System; namespace PE { public class PE002 { public static void Calc() { const int n = 4000000; int a = 1; int b = 2; int sum = 2; while (b <= n) { int tmp = a + b; a = b; b = tmp; if (tmp % 2 == 0) sum += tmp; } Console.Wri…

varに戸惑う

C# の var の使いどころに戸惑っている。 これまで書いたことのある言語は、C++, Java, Python で、C# の var のような型推論は初めての体験。 練習のためにどう書くの問題を解いてみた。 第13回オフラインリアルタイムどう書くの参考問題。C#で解く。 - Qii…