All pastes #834203 Raw Edit

Untitled

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

namespace EulerProject
{
    class Solution174
    {
        private int hollows(int n, bool show) {
            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[] types=new int[10];
            for (int i = 1; i <= 1000000; ++i) {
                int L = hollows(i, false);
                if (L >= 1 && L <= 10) types[L - 1]++;
            }
            int sum = 0;
            for (int i = 0; i < 10; ++i) {
                Console.WriteLine("N(" + (i + 1) + ")=" + types[i]);
                sum += types[i];
            }
            Console.WriteLine("Sum = " + sum);
        }
    }
    class Program
    {
        static void Main(string[] args) {
            new Solution174();
            Console.Read();
        }
    }
}