Project Euler #38: Pandigital multiples

  • + 0 comments

    Here is my 100 points C# Solutions

    using System;
    
    class Solution {
        static bool IsPandigital(int n, int k) {
            int i = 1;
            string numbers = "";
            
            while (true) {
                numbers += (n * i).ToString();
                if (numbers.Length >= k) {
                    break;
                }
                i++;
            }
            
            if (numbers.Length == k && IsSubset(numbers, k)) {
                return true;
            }
            return false;
        }
    
        static bool IsSubset(string numbers, int k) {
            for (int a = 1; a <= k; a++) {
                if (!numbers.Contains(a.ToString())) {
                    return false;
                }
            }
            return true;
        }
    
        static void Main(string[] args) {
            string[] input = Console.ReadLine().Split();
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);
    
            for (int i = 2; i < n; i++) {
                if (IsPandigital(i, k)) {
                    Console.WriteLine(i);
                }
            }
        }
    }