## Fast algorithm

```
n = 5566
IntegerPart[10 Mod[7 PowerMod[10, n - 1, 101], 101]/101]
```

A brute force approach (see also these posts on stackoverflow :) ) may
be fine for the current problem, but what if `n`

is a huge number? The only possibility apart from guessing the periodic sequence of numbers as mgamer suggested would be to use *modular arithmetics*. Let me explain my answer. In contrast to the original post we put the number of interest not in the last digit of the **integer part**, but in the first digit of the **fractional part**. Conveniently, the fractional part can be computed as a reminder, or for higher efficiency by `PowerMod`

.

Let us compare the timing of the two methods:

```
n = 556612345;
Mod[IntegerPart[7 10^n/101], 10] // Timing
(*{10.447660, 3}*)
IntegerPart[10 Mod[7 PowerMod[10, n - 1, 101], 101]/101] // Timing
(*{0.000016, 3}*)
```

The time difference is obvious!

## Explanation

Let us consider another example, we compute the `n=6`

digit of the `7/121`

fraction.

```
n = 6
N[7/121, 30]
```

0.05785**1**2396694214876033057851240.

In the original post the sought digit is the last digit of the integer part:

```
N[7 10^n/121, 20]
```

5785**1**.239669421487603

whereas in my solution it is the first digit in the fractional part

```
N[Mod[7*10^(n - 1), 121]/121, 20]
```

0.**1**2396694214876033058 .

It is further used that `Mod[a 10^b,c]=Mod[a PowerMod[10,b,c],c]`

.

## Reusable function

As requested in the comments, a reusable function can be provided:

```
Clear[nthDigitFraction];
nthDigitFraction[numerator_Integer, denominator_Integer, n_Integer,
base_Integer: 10] /; n > 0 && base > 0 && denominator != 0 :=
Module[{a = Abs[numerator], b = Abs[denominator]},
IntegerPart[base Mod[a PowerMod[base, n - 1, b], b]/b]]
```

8The best way to find this digit is in my opinion to calculate it. Since 7/101 ist periodic and so every digit in position n for which mod(n,4)=2 is 6. And mod(5566,4)=2. – mgamer – 2016-08-29T04:34:37.370

1@mgamer great point. Intelligence wins over brute force. – Mr.Wizard – 2016-08-29T04:37:09.523

2@Mr.Wizard: Was about to post an answer using just that (though it's

notas simple as just a`Mod`

- one must account for possible non-repeating digits before repeat starts), but not clear if OP needs merit the extra code. It will be orders of magnitude faster when going out millions+ digits, but for less, probably no real advantage over your answer... – ciao – 2016-08-29T04:48:00.813