E
E
ex3mpl2020-08-23 11:14:10
Python
ex3mpl, 2020-08-23 11:14:10

How to solve a logic and math problem in Python?

hello to all who opened this question, thank you for taking the time to suffer for a
very long time with one unsolved problem, I just can’t figure out how to approach it, through what formula to solve it and how to solve it at all, so I resorted to asking for help from those who understand this much better.

Here's the challenge itself:

Write a program that will help you create a training plan to prepare for a marathon. It receives as input the number of kilometers on the planned marathon, how many the user plans to run on the first day of training, and by what percentage he plans to increase this distance every day. At the output, the program should give out how many days the user will need to prepare to run the target number of kilometers.

read that it is possible to do this task through the formula of the sum of the first n-terms of a geometric progression, but the answer is given the wrong

answer example:

input format:
12
3
10

output format:
16

thanks everyone for the help in the solution in advance :)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
kurrbanov, 2020-08-24
@ex3mpl

Let
n be the number of kilometers to be run in the marathon.
s - number of km. in 1 workout.
p - number. percent by which s is increased.
Let's make a mat. model. We get:
Day 1: S
Day 2: (1 + p/100) * S
Day 3: (1 + p/100)^2 * S
...
Final formula: (1 + p/100)^k * s > = n; s >= 0, so we divide by it. k is the number of days.
We get: k \u003d log 1 + p / 100 (n / s) + 1. We add one, because we still have to calculate the first day.
The code:

import math

n = int(input())
s = int(input())
p = int(input())

ans = round(math.log((n / s), (1 + p / 100))) + 1

print(ans)

G
Grigory Boev, 2020-08-23
@ProgrammerForever

b1 - kilometers on the first day
p - increase in %
D - marathon length
Solution:
1) Progression denominator:

q = 1+p/100

2) The sum of the first members of the progression:
S = b1*(1-q^n)/(1-q)

S >= D

b1*(1-q^n)/(1-q) >= D

q^n >= 1-D*(1-q)/b1

log_q(q^n) >= log_q(1-D*(1-q)/b1)

n >= log_q(1-D*(1-q)/b1)

M
mr_Try, 2020-08-24
@mr_Try

Loop Solution

S = int(input(""))
s0 = int(input(""))
perc = int(input(""))
day = 1

while S > s0:
    day += 1
    s0 = s0 + s0 * perc / 100
print(day, "дней")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question