How to find the smallest number with just 0 and 1 which is divided by a given number?

后端 未结 11 1376
情话喂你
情话喂你 2020-11-29 22:44

Every positive integer divide some number whose representation (base 10) contains only zeroes and ones.

One can prove that:

Consider the numbers 1, 11, 111,

11条回答
  •  猫巷女王i
    2020-11-29 23:12

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication2
    {
        class Class1
        {
            public static void Main()
            {
    
                List possibleCombination = new List();
    
                for (int i = 2; i < 10000; i++)
                {
                    possibleCombination.Add(Convert.ToString(i, 2));
                }
    
                var input = Console.ReadLine();
    
    
    
                long output = 0;
    
                foreach (var item in possibleCombination)
                {
                    if (Convert.ToInt64(item) % Convert.ToInt64(i) == 0)
                    {
                        output = Convert.ToInt64(item);
                        break;
                    }
                }
    
                Console.WriteLine(output);
    
                Console.ReadLine();
            }
    
        }
    }
    

提交回复
热议问题