Блог пользователя AnupamRoy

Автор AnupamRoy, история, 18 месяцев назад, По-английски

https://mirror.codeforces.com/problemset/problem/1175/A

for avobe problem as editorial the solution is here . but it gives worng answer what is the problem in my python code

for i in range(int(input())): n,m=map(int,input().split()) p=0 while 1: if n%m==0: n/=m n=int(n) p+=1 else: r=(n%m) n-=r p+=r if n==0: break print(p)

  • Проголосовать: нравится
  • -8
  • Проголосовать: не нравится

»
18 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

n /= m should be n //= m.

This is because the / operator in python is floating point division and using this converts your numbers to floats. Floating point numbers don't have enough precision to store big integers. // is integer division, which is precise and that is what you want.