ZhenlongDai/ACPR huggingface dataset:
Problem: p04014
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
import sys
sys.setrecursionlimit(10000)
input = stdin.readline

n = int(input().rstrip())
s = int(input().rstrip())

def f(b, n):
	if n < b:
		return n
	else:
		return f(b, int(n/b)) + (n % b)
if s == n:
	print(n+1)
else:
	for i in range(2, int(n**(1/2))+1):
		if f(i, n) == s:
			print(i)
			break
	else:
		for p in range(1, int(n**(1/2))+1):
			if (n-s) % p == 0:
				b = (n-s)/p + 1
				if b >= 2 and f(b, n) == s:
					print(int(b))
					break
			else:
				continue
		else:
			print(-1)

Failing test case input:
87654
438

Expected output:
317


Actual output:
87217


Fixed submission (verdict: Accepted):
from sys import stdin
import sys
sys.setrecursionlimit(10000)
input = stdin.readline

n = int(input().rstrip())
s = int(input().rstrip())

def f(b, n):
	if n < b:
		return n
	else:
		return f(b, int(n/b)) + (n % b)
if s == n:
	print(n+1)
else:
	for i in range(2, int(n**(1/2))+1):
		if f(i, n) == s:
			print(i)
			break
	else:
		for p in range(int(n**(1/2)), 0, -1):
			if (n-s) % p == 0:
				b = (n-s)/p + 1
				if b >= 2 and f(b, n) == s:
					print(int(b))
					break
			else:
				continue
		else:
			print(-1)

Problem: p04014
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
s=int(input())

b_ans=1

if n==s:
  b_ans=n+1
if b_ans==1:
  for b in range(2,int(n**0.5)+1):
    nn=n
    st=[]
    while(nn>0):
      st.append(nn%b)
      nn=(nn-st[-1])/b
  
    if sum(st)==s:
      b_ans=b
      break


if b_ans==1:
  for p in range(1,int(n**0.5)):
    b=int(n/p)
    q=n-p*b
    if s==p+q:
      b_ans=b
      break

if b_ans!=1:
  print(b_ans)
else:
  print(-1)

Failing test case input:
87654
438

Expected output:
317


Actual output:
369


Fixed submission (verdict: Accepted):
n=int(input())
s=int(input())

b_ans=1



if n==s:
  b_ans=n+1
if b_ans==1:
  for b in range(2,int(n**0.5)+1):
    nn=n
    st=[]
    while(nn>0):
      st.append(nn%b)
      nn=(nn-st[-1])/b
  
    if sum(st)==s:
      b_ans=b
      break

if b_ans==1:
  for p in range(int(n**0.5),0,-1):
    b=(n-s+p)/p

    if b.is_integer() and 0<=s-p<b and b>n**0.5:
      b_ans=int(b)
      break

if b_ans!=1:
  print(b_ans)
else:
  print(-1)
Problem: p04014
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

def func(b,n):
  if b > n:
    return n
  else:
    return func(b, math.floor(n/b)) + (n % b)

def _func(b,n):
  x = n
  ret = 0
  while True:
    if b > x:
      return ret + x
    else:
      ret += x % b
      x = math.floor(x/b)

def solve(n,s):
  if n == s:
    return n+1
  for b in range(2,math.floor(math.sqrt(n))+1):
    if _func(b,n) == s:
      return b

  for p in range(1,math.floor(math.sqrt(n))+1):
    if (n-s) % p == 0:
      b = int((n-s)/p)+1
      if b < 2:
        continue
      if _func(b, n) == s:
        return b

  return -1

if __name__  == "__main__":
  n = int(input())
  s = int(input())
  ans = solve(n,s)
  print(ans)


Failing test case input:
87654
5894

Expected output:
8177


Actual output:
81761


Fixed submission (verdict: Accepted):
import math

def func(b,n):
  if b > n:
    return n
  else:
    return func(b, math.floor(n/b)) + (n % b)

def _func(b,n):
  x = n
  ret = 0
  while True:
    if b > x:
      return ret + x
    else:
      ret += x % b
      x = math.floor(x/b)

def solve(n,s):
  if n == s:
    return n+1
  ans = float('inf')
  for b in range(2,math.floor(math.sqrt(n))+1):
    if _func(b,n) == s:
      return b

  for p in range(1,math.floor(math.sqrt(n))+1):
    if (n-s) % p == 0:
      b = int((n-s)/p)+1
      if b < 2:
        continue
      if _func(b, n) == s:
        ans = min(ans, b)

  if ans < float('inf'):
    return ans
  else:
    return -1

if __name__  == "__main__":
  n = int(input())
  s = int(input())
  ans = solve(n,s)
  print(ans)

Problem: p04014
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
s=int(input())

b_ans=1



if n==s:
  b_ans=n+1
if b_ans==1:
  for b in range(2,int(n**0.5)+1):
    nn=n
    st=[]
    while(nn>0):
      st.append(nn%b)
      nn=(nn-st[-1])/b
  
    if sum(st)==s:
      b_ans=b
      break


if b_ans==1:
  for p in range(int(n**0.5),0,-1):
    b=(n-s+p)/p

    if b.is_integer() and s-p<b:
      b_ans=int(b)
      break

if b_ans!=1:
  print(b_ans)
else:
  print(-1)

Failing test case input:
87654
7

Expected output:
12522


Actual output:
660


Fixed submission (verdict: Accepted):
n=int(input())
s=int(input())

b_ans=1



if n==s:
  b_ans=n+1
if b_ans==1:
  for b in range(2,int(n**0.5)+1):
    nn=n
    st=[]
    while(nn>0):
      st.append(nn%b)
      nn=(nn-st[-1])/b
  
    if sum(st)==s:
      b_ans=b
      break

if b_ans==1:
  for p in range(int(n**0.5),0,-1):
    b=(n-s+p)/p

    if b.is_integer() and 0<=s-p<b and b>n**0.5:
      b_ans=int(b)
      break

if b_ans!=1:
  print(b_ans)
else:
  print(-1)
Problem: p04014
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

def func(b,n):
  if b > n:
    return n
  else:
    return func(b, math.floor(n/b)) + (n % b)

def _func(b,n):
  x = n
  ret = 0
  while True:
    if b > x:
      return ret + x
    else:
      ret += x % b
      x = math.floor(x/b)

def solve(n,s):
  for b in range(2,math.floor(math.sqrt(n))+1):
    if _func(b,n) == s:
      return b

  for p in range(1,math.floor(math.sqrt(n))+1):
    if (n-s) % p == 0:
      b = int((n-s)/p)+1
      if b < 2:
        continue
      if _func(b, n) == s:
        return b

  return -1

if __name__  == "__main__":
  n = int(input())
  s = int(input())
  ans = solve(n,s)
  print(ans)


Failing test case input:
87654
241

Expected output:
1434


Actual output:
87414


Fixed submission (verdict: Accepted):
import math

def func(b,n):
  if b > n:
    return n
  else:
    return func(b, math.floor(n/b)) + (n % b)

def _func(b,n):
  x = n
  ret = 0
  while True:
    if b > x:
      return ret + x
    else:
      ret += x % b
      x = math.floor(x/b)

def solve(n,s):
  if n == s:
    return n+1
  ans = float('inf')
  for b in range(2,math.floor(math.sqrt(n))+1):
    if _func(b,n) == s:
      return b

  for p in range(1,math.floor(math.sqrt(n))+1):
    if (n-s) % p == 0:
      b = int((n-s)/p)+1
      if b < 2:
        continue
      if _func(b, n) == s:
        ans = min(ans, b)

  if ans < float('inf'):
    return ans
  else:
    return -1

if __name__  == "__main__":
  n = int(input())
  s = int(input())
  ans = solve(n,s)
  print(ans)

Problem: p04014
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
s=int(input())

b_ans=1



if n==s:
  b_ans=n+1
if b_ans==1:
  for b in range(2,int(n**0.5)+1):
    nn=n
    st=[]
    while(nn>0):
      st.append(nn%b)
      nn=(nn-st[-1])/b
  
    if sum(st)==s:
      b_ans=b
      break


if b_ans==1:
  for p in range(int(n**0.5),0,-1):
    b=int(n/p)
    q=n-p*b
    if s==p+q and q<b:
      b_ans=b
      break

if b_ans!=1:
  print(b_ans)
else:
  print(-1)

Failing test case input:
87654
264

Expected output:
972


Actual output:
-1


Fixed submission (verdict: Accepted):
n=int(input())
s=int(input())

b_ans=1



if n==s:
  b_ans=n+1
if b_ans==1:
  for b in range(2,int(n**0.5)+1):
    nn=n
    st=[]
    while(nn>0):
      st.append(nn%b)
      nn=(nn-st[-1])/b
  
    if sum(st)==s:
      b_ans=b
      break

if b_ans==1:
  for p in range(int(n**0.5),0,-1):
    b=(n-s+p)/p

    if b.is_integer() and 0<=s-p<b and b>n**0.5:
      b_ans=int(b)
      break

if b_ans!=1:
  print(b_ans)
else:
  print(-1)
Problem: p04014
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math, sys

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

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, math.floor(n/b)) + n % b

if s == n:
    print(n+1)
    sys.exit()


for b in range(2, math.ceil(math.sqrt(n))):
    
    if(f(b, n) == s):
        print(b)
        sys.exit()


for p in range(1, math.ceil(math.sqrt(n))):
    
    b = int((n-s)/p) + 1
    if(b >= 2 and f(b, n) == s):
        print(b)
        sys.exit()

print("-1")


Failing test case input:
31415926535
7

Expected output:
4487989505


Actual output:
31415926529


Fixed submission (verdict: Accepted):
import math, sys

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

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, math.floor(n/b)) + n % b

if s == n:
    print(n+1)
    sys.exit()


for b in range(2, math.floor(math.sqrt(n))+1):
    
    if(f(b, n) == s):
        print(b)
        sys.exit()


for p in range(1, math.floor(math.sqrt(n))+1):
    
    _p = math.floor(math.sqrt(n))+1-p
    b = int((n-s)/_p) + 1
    if(b >= 2 and f(b, n) == s):
        print(b)
        sys.exit()

print("-1")

Problem: p04014
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math, sys

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

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, math.floor(n/b)) + n % b

if s == n:
    print(n+1)
    sys.exit()

print(2, math.ceil(math.sqrt(n)))
for b in range(2, math.floor(math.sqrt(n))+1):
    
    if(f(b, n) == s):
        print(b)
        sys.exit()

print(math.floor(math.sqrt(n))-1)
for p in range(1, math.ceil(math.sqrt(n))):
    
    b = int((n-s)/p) + 1
    if(b >= 2 and f(b, n) == s):
        print(b)
        sys.exit()

print("-1")


Failing test case input:
87654
264

Expected output:
972


Actual output:
2 297
295
87391


Fixed submission (verdict: Accepted):
import math, sys

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

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, math.floor(n/b)) + n % b

if s == n:
    print(n+1)
    sys.exit()


for b in range(2, math.floor(math.sqrt(n))+1):
    
    if(f(b, n) == s):
        print(b)
        sys.exit()


for p in range(1, math.floor(math.sqrt(n))+1):
    
    _p = math.floor(math.sqrt(n))+1-p
    b = int((n-s)/_p) + 1
    if(b >= 2 and f(b, n) == s):
        print(b)
        sys.exit()

print("-1")
Problem: p03505
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import math
k,a,b = map(int, input().split())
if a >= k:
    print(1)
else:
    if a <= b:
        print(-1)
    else:
        print((2*math.ceil((k-a)/(a-b)))+1)

Failing test case input:
1100010010001000000 2 -11

Expected output:
169232309230923079


Actual output:
169232309230923073


Fixed submission (verdict: Accepted):

from decimal import *
import math
k,a,b = map(int, input().split())
if a >= k:
    print(1)
else:
    if a <= b:
        print(-1)
    else:
        print(2*math.ceil(Decimal(k-a)/Decimal(a-b))+1)

Problem: p03505
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
from decimal import *

numbers = [int(i) for i in input().split()]

diff = numbers[1] - numbers[2]

if diff <= 0:
    print("-1")
elif numbers[0] <= numbers[1]:
    print("1")
else:
    rating = 0
    count = 0
    print(math.ceil(Decimal(numbers[0] - numbers[1]) / diff) * 2 + 1)

Failing test case input:
31 144 600

Expected output:
1


Actual output:
-1


Fixed submission (verdict: Accepted):
import math
from decimal import *

numbers = [int(i) for i in input().split()]

diff = numbers[1] - numbers[2]

if numbers[0] <= numbers[1]:
    print("1")
elif diff <= 0:
    print("-1")
else:
    print(math.ceil(Decimal(numbers[0] - numbers[1]) / diff) * 2 + 1)

Problem: p03505
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import math
K, A, B = list(map(int, input().split()))

if (A >= K):
    print(1)
    sys.exit()
elif (A - B) <= 0:
    print(-1)
    sys.exit()
d = A - B

p = K-A
q = p/d
if ((p % d) != 0):
    q += 1
print(2*q + 1)

Failing test case input:
1100000000100000000 4 0

Expected output:
550000000049999999


Actual output:
5.5000000005e+17


Fixed submission (verdict: Accepted):
import sys
import math
K, A, B = list(map(int, input().split()))
 
if (A >= K):
    print('1')
    sys.exit()
elif (A - B) <= 0:
    print('-1')
    sys.exit()
d = A-B
p = K-A
q = int(p
if ((p % d) != 0):
    q += 1
print(str(2*q + 1))

Problem: p03505
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import ceil
k,a,b=map(int,input().split())
k-=a
if k<=0:
  print(1)
elif a>b:
  print(1+ceil(k/(a-b))*2)
else:
  print(-1)

Failing test case input:
1100110001111001010 2 0

Expected output:
1100110001111001009


Actual output:
1100110001111000961


Fixed submission (verdict: Accepted):
from math import ceil
k,a,b=map(int,input().split())
if k<=a:
  print(1)
elif a>b:
  print(1+(k-b-1)
else:
  print(-1)

Problem: p03505
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
K,A,B=map(int,input().split())
if A>=K:
  print(1)
elif A-B>0:
  print(1+math.ceil((K-A)/(A-B))*2)
else:
  print(-1)

Failing test case input:
1100100001011001000 2 1

Expected output:
2200200002022001997


Actual output:
2200200002022001921


Fixed submission (verdict: Accepted):
from decimal import *
import math
K,A,B=map(int,input().split())
if A>=K:
  print(1)
elif A-B>0:
  print(1+math.ceil(Decimal(K-A)/Decimal(A-B))*2)
else:
  print(-1)
Problem: p03505
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import math
K, A, B = list(map(int, input().split()))

if A >= K:
    print(1)
    sys.exit()
elif (A - B) <= 0:
    print(-1)
    sys.exit()
d = A - B

p = K-A
q = math.ceil(float(p)/d)


Failing test case input:
1101000010100000000 4 0

Expected output:
550500005049999999


Actual output:

Fixed submission (verdict: Accepted):
import sys
import math
K, A, B = list(map(int, input().split()))
 
if (A >= K):
    print('1')
    sys.exit()
elif (A - B) <= 0:
    print('-1')
    sys.exit()
d = A-B
p = K-A
q = int(p
if ((p % d) != 0):
    q += 1
print(str(2*q + 1))

Problem: p03505
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import math
K, A, B = list(map(int, input().split()))

if A >= K:
    print(1)
    sys.exit()
elif (A - B) <= 0:
    print(-1)
    sys.exit()
d = A - B

p = K-A
q = math.ceil(float(p)/d)
print(2*q + 1)


Failing test case input:
0100001110110000011 2 0

Expected output:
100001110110000011


Actual output:
100001110110000017


Fixed submission (verdict: Accepted):
import sys
import math
K, A, B = list(map(int, input().split()))
 
if (A >= K):
    print('1')
    sys.exit()
elif (A - B) <= 0:
    print('-1')
    sys.exit()
d = A-B
p = K-A
q = int(p
if ((p % d) != 0):
    q += 1
print(str(2*q + 1))

Problem: p03505
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import math
K, A, B = list(map(int, input().split()))

if (A >= K):
    print(1)
    sys.exit()
elif (A - B) <= 0:
    print(-1)
    sys.exit()
d = A - B

p = K-A
q = p/d
if ((p % d) != 0):
    q += 1
print(int(2*q + 1))

Failing test case input:
0100001110110000011 2 -2

Expected output:
50000555055000007


Actual output:
50000555055000008


Fixed submission (verdict: Accepted):
import sys
import math
K, A, B = list(map(int, input().split()))
 
if (A >= K):
    print('1')
    sys.exit()
elif (A - B) <= 0:
    print('-1')
    sys.exit()
d = A-B
p = K-A
q = int(p
if ((p % d) != 0):
    q += 1
print(str(2*q + 1))

Problem: p03505
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

numbers = [int(i) for i in input().split()]

max_number = math.pow(10,18)

diff = numbers[1] - numbers[2]

if numbers[0] > diff * max_number:
    print("-1")
else:
    rating = 0
    count = 0
    print(math.ceil(numbers[0] / diff) * 2 - 1)

Failing test case input:
1100100010001000000 1 -2

Expected output:
733400006667333335


Actual output:
733400006667333375


Fixed submission (verdict: Accepted):
import math
from decimal import *

numbers = [int(i) for i in input().split()]

diff = numbers[1] - numbers[2]

if numbers[0] <= numbers[1]:
    print("1")
elif diff <= 0:
    print("-1")
else:
    print(math.ceil(Decimal(numbers[0] - numbers[1]) / diff) * 2 + 1)
Problem: p03505
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import math
K, A, B = list(map(int, input().split()))

if A >= K:
    print(1)
    sys.exit()
elif (A - B) <= 0:
    print(-1)
    sys.exit()
d = A - B

p = K-A
q = p/d
if (p % d) != 0:
    q += 1
print(2*q + 1)

Failing test case input:
0100001110111000010 4 1

Expected output:
66667406740666673


Actual output:
6.666740674066667e+16


Fixed submission (verdict: Accepted):
import sys
import math
K, A, B = list(map(int, input().split()))
 
if (A >= K):
    print('1')
    sys.exit()
elif (A - B) <= 0:
    print('-1')
    sys.exit()
d = A-B
p = K-A
q = int(p
if ((p % d) != 0):
    q += 1
print(str(2*q + 1))