Calculate A(N) / B(N) with C(N) digits

Pyth, 60 57 58 bytes

.[K`.Rchu,eGsGQjT7e.ftPZQ)Je/u+/*GHhyHy^TQr^T3ZZT\0+xK\.hJ

Test harness

It's pretty straightforward - calculate pi, the fibonacci series and the composites, round to C(n) digits, pad to C(n) digits plus the location of the decimal point digits, done.

A(n): hu,eGsGQjT7

B(n): e.ftPZQ)

C(n): e/u+/*GHhyHy^TQr99ZZT

60 -> 57: Cleaned up the n = 1 special case in the pi calculation.

57 -> 58: Wasn't using high enough precsion for pi for the entire input range - increased 99 iterations to 1000 iterations.

Note on rounding: This uses Python's "nearest even" rounding system, rather than the OP specified "towards infinity" system. However, the difference only matters if the digits immediately following the rounding point are 5000..., e.g. 1.25 rounded to 1 digit. I checked the input range, and this never happens, so the correct result is alway returned.


PowerShell, 420 Bytes (ayyyyyyyy) 378 Bytes

param($n);[int[]]$p="03141592653589793238462643383279502884197169399375"-Split'';$a=@(0,3,4);for($i=3;$i-lt50;$i++){$a+=$a[$i-1]+$a[$i-2]};$c=[char[]]"00001010111010111010111011111010111110111010111011111011111010111110111";$b=@(0);for($i=4;$i-le70;$i++){if($c[$i]-eq'1'){$b+=$i}};[double]$r=$a[$n]/$b[$n];$q=$p[$n+1];$s="";(0..($q-1))|%{$s+="0"};([math]::Round($r,$q,[MidpointRounding]::AwayFromZero)).ToString("0.$s")

Thanks to isaacg for saving 41 bytes, for calculating how the question does rounding. Means I didn't have to include the horrendous [MidpointRounding]::AwayFromZero and didn't need to explicitly cast as a [double].

This one was great fun!

Expanded:

# Take input N
param($n)

# First digits of pi, stored as integer array
[int[]]$p="03141592653589793238462643383279502884197169399375"-Split''

# Fibonacci sequence A(N)
$a=@(0,3,4)
for($i=3;$i-lt50;$i++){
  $a+=$a[$i-1]+$a[$i-2]
}

# Zero-indexed bitmask for if the n-th integer is composite (1) or not (0)
$c=[char[]]"00001010111010111010111011111010111110111010111011111011111010111110111"

# Populate B(N) as an array using the $c mask
$b=@(0)
for($i=4;$i-le70;$i++){
  if($c[$i]-eq'1'){
    $b+=$i
  }
}

# Calculation Time!
$r=(a($n))/$b[$n]

# A small golf, as $p[$n+1] gets used a couple times
$q=$p[$n+1]

# Need to generate a string of zeroes for padding
$s=""
(0..($q-1))|%{$s+="0"}

# Round the number, then send it to a string so we get the necessary number of zeroes
([math]::Round($r,$q)).ToString("0.$s")

Recursion in PowerShell is ... slow, shall we say, so we have to build A(N) the other direction and store it into an array, then index it.


OLD

Also, holy cow, did the output requirements kill this. PowerShell defaults to rounding-to-nearest a/k/a banker's rounding, which necessitates utilizing the extraordinarily verbose [MidpointRounding]::AwayFromZero to switch rounding styles. On top of that, we then needing to pad trailing zeroes, if any. Those two requirements combined to turn the last couple of lines from 20 Bytes [math]::Round($r,$q) to 102 Bytes (from the $s="" to +$s)) ... wow.