using System.Collections.Generic;
static void Main(string[] args)
BigInteger inicio = BigInteger.Parse("10000");
BigInteger fin = BigInteger.Parse("1000000");
HashSet<BigInteger> numeros = GenerarNumeros(inicio, fin);
Console.WriteLine("Lista de números válidos:");
foreach (BigInteger numero in numeros)
Console.WriteLine(numero);
static HashSet<BigInteger> GenerarNumeros(BigInteger inicio, BigInteger fin)
HashSet<BigInteger> numeros = new HashSet<BigInteger>();
for (BigInteger i = inicio; i <= fin; i++)
string numberString = i.ToString();
bool descartarTodo = false;
for (int j = 0; j < numberString.Length; j++)
string rotatedString = RotateWithoutMovingZeros(numberString, j);
BigInteger rotatedNumber = BigInteger.Parse(rotatedString);
for (int j = 0; j < numberString.Length; j++)
string rotatedString = RotateWithoutMovingZeros(numberString, j);
BigInteger rotatedNumber = BigInteger.Parse(rotatedString);
if (rotatedNumber >= inicio && rotatedNumber <= fin)
numeros.Add(rotatedNumber);
static string RotateWithoutMovingZeros(string s, int positions)
char[] rotated = s.ToCharArray();
List<int> nonZeroPositions = new List<int>();
for (int i = 0; i < s.Length; i++)
int n = nonZeroPositions.Count;
for (int i = 0; i < n; i++)
int newPos = nonZeroPositions[(i + positions) % n];
rotated[newPos] = s[nonZeroPositions[i]];
return new string(rotated);