典型90問    次の典型90問へ    前の典型90問へ

典型90問 085 Multiplication 085(★4)


問題へのリンク


C#のソース

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("42");
            //5
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("7");
            //1
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("192");
            //16
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        long N = long.Parse(InputList[0]);

        long Answer = 0;
        for (long A = 1; A * A * A <= N; A++) {
            if (N % A > 0) continue;
            for (long B = A; A * B * B <= N; B++) {
                if (N % (A * B) > 0) {
                    continue;
                }

                long Syou = N / (A * B);
                if (B <= Syou) {
                    Answer++;
                }
                else {
                    break;
                }
            }
        }
        Console.WriteLine(Answer);
    }
}


解説

枝切りを付けつつ、全探索してます。