All pastes #834221 Raw Edit

Miscellany

public text v1 · immutable
#834221 ·published 2007-12-28 00:47 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Text;

namespace EulerProject
{
    class Solution174
    {
        private int L(int n, bool show) {
            if ((n % 4) != 0 || (n < 8)) return 0;
            int nSols = 0;
            for (int r = 2; n > r * r; r += 2) {
                int a1 = (n + r * r), a = a1 / 2 / r;
                if (a * 2 * r != a1) continue;
                if (a <= r) continue;
                if (show)
                    Console.WriteLine(a + "^2 - " + (a - r) + "^2 = " + n);
                nSols++;
            }
            return nSols;
        }
        public Solution174() {
            int[] typeCounts=new int[10];
            for (int i = 1; i <= 1000000; ++i) {
                int iL = L(i, false);
                if (iL >= 1 && iL <= 10) typeCounts[iL - 1]++;
            }
            int sum = 0;
            for (int i = 0; i < 10; ++i) {
                Console.WriteLine("N(" + (i + 1) + ")=" + typeCounts[i]);
                sum += typeCounts[i];
            }
            Console.WriteLine("Sum = " + sum);
        }
    }
    class Program
    {
        static void Main(string[] args) {
            new Solution174();
            Console.Read();
        }
    }
}