Home‎ > ‎ProgComp‎ > ‎ProgComp 2012 Sample Tasks‎ > ‎

Task 1. Two out of three ain't bad

# Task 1 2012: two out of three aint bad

from math import exp
# Largest value of pk

k=2
threshold = float(0.666667000); #set the limiting value / threshold to stop calc

def calcPk(k):
    k3=pow(k,3);
    top=((k3)-1.0)
    bot=((k3)+1.0);
    ans=(top/bot);
    #print('k= {}, Pk= {}'.format(k,ans));
    return ans;

Pk = calcPk(k); # calc the first Pk in series
while True:
    if (Pk*calcPk(k+1) < threshold):
        break;
    k  +=1;
    Pk *= calcPk(k);

print('k= {}, Pk= {}'.format(k,Pk));

Comments