class Program
{
static string RepeatingPattern(int m, int n)
{
int i = 0;
int j = (int)Math.Log10(m);
int r = 0;
HashSet
string outt = ( m < n ) ? "0." : "";
int num = m;
do {
num = Int32.Parse(("" + num).Substring(i, j - i + 1));
char o;
if (num < n)
{
int sizeN = (int)Math.Log10(n);
int sizeNum = (int)Math.Log10(num);
int diff = sizeN - sizeNum;
num = num * ((int)Math.Pow(10, diff));
outt += new String('0', diff);
j = j + diff;
num *= 10;
j++;
}
else
{
outt = "" + (num / n) + ".";
}
r = num % n;
int d = num / n;
num = r;
i = 0;
j = (int)Math.Log10(num);
if (remainders.Contains(r))
{
break;
}
else
{
outt += ("" + d);
remainders.Add(r);
}
} while( r != 0);
return outt;
}
static void Main(string[] args)
{
string r;
// RepeatingPattern(5, 74);
// RepeatingPattern(1, 81);
r= RepeatingPattern(1, 7);
Console.WriteLine(r);
r = RepeatingPattern(22, 7);
Console.WriteLine(r);
r = RepeatingPattern(1, 97);
Console.WriteLine(r);
}
}
No comments:
Post a Comment