matarillo #7649(2008/09/17 02:17 GMT) [ C# ] Rating1/1=1.00
ちゃんと計算してないけど、時間計算量はO(n logn)、空間計算量はO(1)ぐらい? 再帰してるから空間計算量はO(logn)なのかな。
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
class P { static void Main(string[] args) { for (int i = 1, c = 0; c < 100; i++) { int[] f = F(i); if (f != null) { ++c; System.Console.WriteLine ("{0} = 2^{1} * 3^{2} * 5^{3}", i, f[2], f[3], f[5]); } } } static int[] F(int n) { if (n == 1) return new int[6]; int[] a = { 2, 3, 5 }; foreach (int d in a) if (n % d == 0) { int[] r = F(n / d); if (r == null) return null; ++r[d]; return r; } return null; } }
Rating1/1=1.00-0+
[ reply ]
matarillo
#7649()
[
C#
]
Rating1/1=1.00
ちゃんと計算してないけど、時間計算量はO(n logn)、空間計算量はO(1)ぐらい? 再帰してるから空間計算量はO(logn)なのかな。
Rating1/1=1.00-0+
[ reply ]