solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
a,b=map(int,input().split()) h=a l=a d=0 while l>=b: d=l%b l=l//b h+=l l=d+l print(h+l//b)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int t = 0, ans = 0; while (n != 0) { ans++; t++; n--; if (t == k) { n++; t -= k; } } cout << ans; return 0; }
7
CPP
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): n,m = LI() t = 0 r = 0 while 1: if n == 0: return r r += n t += n n = t // m t %= m return -1 print(main())
7
PYTHON3
a,b=map(int,input().split()) s=a while 1: if a>=b: a-=b a+=1 s+=1 else: break print(s)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, tmp; cin >> a >> b; int cnt = 0; tmp = a; while (a > 0) { cnt++; a--; if (tmp - a == b) { a++; tmp = a; } } cout << cnt; }
7
CPP
a,b=map(int,input().split()) k=a while a//b>0: k=k+a//b a=a//b+a%b print(k)
7
PYTHON3
n,m = map(int,input().split()) resp = 0 while n >= m: resp = resp + m n = n - m n = n + 1 resp = resp + n print(resp)
7
PYTHON3
def candles(m,n): if(m<n): print(m) else: h=m while(m>=n): ans=int(m/n) rem=int(m%n) h=ans+h m=ans+rem print(int(h)) a=[] b=[] a,b=input().split() a=int(a) b=int(b) candles(a,b)
7
PYTHON3
a, b = map(int, input().split()) c, t = 0, 0 while a > 0: c += a t += a a = c // b c -= a * b print(t)
7
PYTHON3
c=input().split(); a=int(c[0]) b=int(c[1]) e=0 f=0 c=0 while True: c+=int(a) if((a+f)<b): break e=int(a+f)%int(b) a=int((int(a)+int(f))/int(b)) f=e print(int(c))
7
PYTHON3
a,b=map(int,input().split()) c=a k=1 while(k!=0): k=a//b q=a-b*k a=k+q c=c+k if(k==0): break print(c)
7
PYTHON3
import sys from collections import Counter n,m=map(int,input().split()) k=n c=0 while n>=m: c+=n//m n=n//m+(n%m) print(c+k)
7
PYTHON3
a,b=map(int,input().strip().split(' ')) res=0 while a>=b: res+=a-a % b a=a//b+a % b res+=a print(res)
7
PYTHON3
a, b = map(int, input().split()) count, current, extra = 0, a, 0 while current > 0: count += current current += extra extra = current % b current = current // b print (count)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, num = 0; cin >> a >> b; num += a; while (a / b > 0) { num += a / b; a = a / b + a % b; } cout << num << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int total, re; cin >> total >> re; int sum = 0; sum += total; while (total >= re) { sum += total / re; total = total / re + total % re; } cout << sum << endl; }
7
CPP
n,m=map(int,input().split()) print(n+((n-1)//(m-1)))
7
PYTHON3
a, b = map(int, input().split()) res = a h = 0 while a > 0: t = (a + h) // b h = (a + h) % b a = t res += a print(res)
7
PYTHON3
a, b = [int(i) for i in input().split()] hours = a while a // b >= 1: hours += a // b a = a // b + a % b print(hours)
7
PYTHON3
a, b = map(int, input().split()) print(((a*b-1)//(b-1)))
7
PYTHON3
'''t=int(input()) for i in range(t): n=int(input()) x=(4*n)-2 print((x//(n+1))) ''' '''n = int(input()) cnt = 1 while n>5: cnt+=1 n-=5 print(cnt) ''' ''' s=input() n = len(s) fl =0 c = "hello" cnt = 0 for i in range(n): if s[i] == c[cnt]: cnt+=1 if cnt == 5: fl = 1 break if fl: print("YES") else: print("NO") ''' ''' n = int(input()) l = list(map(int,input().split())) cnt=1 i =0 m = 1 while i<n-1: if l[i]<=l[i+1]: cnt+=1 if cnt>m: m = cnt else: cnt =1 i+=1 print(m) ''' ''' n = int(input()) s = input() s= s.lower() st= set(s) if len(st) == 26: print("YES") else: print("NO") ''' x,y = map(int,input().split()) print(x+((x-1)//(y-1)))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, w = 0; cin >> a >> b; int h = 1; for (;; h++) { a--; w++; if (w == b) { w = 0; a++; } if (a <= 0) break; } cout << h; }
7
CPP
a, b = map(int, input().split()) hours = 0 candles = a hours += candles left_overs = candles while left_overs >= b: new_candles = left_overs // b left_overs = left_overs % b + new_candles hours += new_candles print(hours)
7
PYTHON3
a,b = map(int,input().split()) def time(a,b,c = 0): if a+c < b: return a elif a == b: return a + 1 else: return a + time((a+c)//b,b,(a+c)%b) print(time(a,b))
7
PYTHON3
m, n = [int(i) for i in input().split()] s = m + (m // n) while m >= n: m = m % n + (m // n) s += m // n print(s)
7
PYTHON3
a,b=[int(x) for x in input().split()] summ = a while a >= b: summ += int(a/b) a = int(a/b) + a - b*int(a/b) print(summ)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, ans = 0; cin >> n >> m; for (int i = 1; n > 0; i++) { ans++; n--; if (i % m == 0) n++; } cout << ans; return 0; }
7
CPP
n,k=map(int,input().split()) hours=0 while n!=0: n-=1 hours+=1 if hours%k==0: n+=1 print(hours)
7
PYTHON3
a,b = map(int,input().split()) print(a+((a-b)//(b-1)+1))
7
PYTHON3
ab = input().split() a = int(ab[0]) b = int(ab[1]) ans = a while a//b != 0: ans += a//b a = a//b + a%b print(ans)
7
PYTHON3
a,b=map(int,input().split()) h=a c=0 while a+c>=b: d=(a+c)%b a=int((a+c)/b) h+=a c=d print(h)
7
PYTHON3
import math a, b = map(int, input().split()) count = a ost = 0 while True : ost = a - b * math.floor( a / b) + ost a = math.floor( a / b) count += a if a == 0 : if ost < b : break else : a = ost ost = 0 print(count)
7
PYTHON3
a,b=[int(x) for x in input().split()] count=0 i=1 while(i<=a): if(i%b==0): a=a+1 i=i+1 print(a)
7
PYTHON3
a, b = map(int, input().split()) t = a while a >= b: q = a//b r = a%b t += q a = q + r print(t)
7
PYTHON3
a,b=map(int,input().split()) count=0 while a>0: a=a-1 count=count+1 if count%b==0: a=a+1 print(count)
7
PYTHON3
a, b = [int(x) for x in input().split()] hours = 0 ctr = 0 while(a > 0): hours += 1 a -= 1 ctr += 1 if ctr == b: ctr = 0 a += 1 print(hours)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int went = 0; int candles = 0; while (a > 0) { candles += a; went += a; a = went / b; went = went % b; } cout << (candles) << endl; ; }
7
CPP
# -*- coding: utf-8 -*- """ Created on Wed May 13 20:04:44 2020 @author: Manav Jain """ a,b=input().split() a,b=[int(a),int(b)] '''hours=a k=1 while k==1: if a<b: break else: a=int(a/b) hours=hours+a print(hours)''' print((a*b-1)//(b-1))
7
PYTHON3
# # # author : samars_diary # # 10:41:49 | 24-09-2020 # # # import sys, os.path if(os.path.exists('input.txt')): sys.stdin = open('input.txt',"r") sys.stdout = open('output.txt',"w") sys.setrecursionlimit(10 ** 5) def i(): return sys.stdin.readline().strip() def ii(): return int(sys.stdin.readline()) def li(): return list(sys.stdin.readline().strip()) def mii(): return map(int, sys.stdin.readline().split()) def lii(): return list(map(int, sys.stdin.readline().strip().split())) #print=sys.stdout.write def solve(): a, b = mii() ; s = a while a>=b: s+=(a//b) a=(a//b)+(a%b) print(s) for _ in range(1): solve()
7
PYTHON3
a,b= map(int,input().split()) if(b>a): print(a) else: count=0 while(a>0): if(a>=b): a=a-b+1 count+=b else: count+=a break print(count)
7
PYTHON3
def main(): a,b = map(int, input().split()) c = a while a//b > 0: c += a//b a = a//b + a%b print(c) if __name__ == '__main__': main()
7
PYTHON3
k = list(map(int, input().split())) m = 0 n = k[0] while(n!=0): m = m+1 n = n-1 if m%k[1]==0: n=n+1 print(m)
7
PYTHON3
a,b = map(int,input().split()) count = a while(a//b!=0): c = a//b a = c+a%b count= count+c print(count)
7
PYTHON3
a,b = map(int,input().split()) res = a while(a >= b): d = a//b res += d m = a % b a = d + m print(res)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const unsigned long long P = 239017, MaxN = 2100000, INF = 1000000000; int main() { int a, b; scanf("%d%d", &a, &b); int ans = 0; int bank = 0; while (a) { ans += a; bank += a; a = bank / b; bank = bank % b; } printf("%d", ans); return 0; }
7
CPP
a,b=map(int,input().split(' ')); print((a*b-1)//(b-1))
7
PYTHON3
m,n=map(int,input().split()) b=1+m a=0 while(m//n>=1): a+=m//n m=m//n+(m-(m//n)*n) print(a+b-1)
7
PYTHON3
a, b, c=map(int, input().split()+[0]) while a>0: a =a-1 c=c+1 if c%b==0: a=a+1 print(c)
7
PYTHON3
a,b=[int(i) for i in input().split()] t=0 new=a left=0 burned=0 while True: if new!=0: t+=new burned=new+left new=int(burned/b) left=burned%b continue else: break print(t)
7
PYTHON3
#include <bits/stdc++.h> int main() { int m, n, c = 0; scanf("%d %d", &m, &n); while (m != 0) { c++; m = m - 1; if (c % n == 0) m = m + 1; } printf("%d", c); return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, i, d = 0; cin >> a >> b; c = (a / b); i = c + (a % b); while (i >= b) { d = (i / b) + d; i = (i / b) + (i % b); } cout << a + c + d; }
7
CPP
a,b = [int(x) for x in input().split()] sum = a while(a>1): sum += a/b a = a/b print(int(sum))
7
PYTHON3
a,b=map(int,input().strip().split()) c=a while a>=b: c+=int(a/b) a=int(a/b)+a%b print(c)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int num, div, rem; cin >> num >> div; int cnt = num; while (num >= div) { rem = num % div; num = num / div; cnt = cnt + num; num = num + rem; } cout << cnt << endl; return 0; }
7
CPP
s = input().split() a = int(s[0]) b = int(s[1]) c = 0 while a > 0: c+=1 a-=1 if c % b == 0: a+=1 print(c)
7
PYTHON3
def doit(number,recycle_number,): if((number)<recycle_number): return number temp=0 temp=number-number%recycle_number number=temp//recycle_number+number%recycle_number return temp+doit(number,recycle_number) numbers=list(map(int,input().split())) print(doit(numbers[0],numbers[1]))
7
PYTHON3
def cf_379a(): a, b = map(int, input().split()) sum_ = a while a >= b: sum_ += a // b a = a - ((a // b) * b) + a // b print(int(sum_)) if __name__ == '__main__': cf_379a()
7
PYTHON3
a, b = [int(x) for x in input().split()] n_burnt = 0 counter = 0 while a > 0: counter += 1 a -= 1 n_burnt += 1 if n_burnt == b: a += 1 n_burnt = 0 print(counter)
7
PYTHON3
x,y=map(int,input().split()) d=(x-1)//(y-1) print(d+x)
7
PYTHON3
a, b = map(int, input().split()) it = a r = 0 while a >= b: r = a % b a = a // b it += a a += r print(it)
7
PYTHON3
a,b=map(int,input().split(' ')) hours=0 hours=hours+a divide=a/b while True: hours=hours+divide if divide/b<=1: divide=divide/b hours=hours+divide print(int(hours)) break else: divide=divide/b continue
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, t = 0, k = 0; cin >> a; cin >> b; while (a) { a--; t++; k++; if (t == b) { a++; t = 0; } } cout << k; cin >> a; }
7
CPP
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230; int main() { int a, b, i, n, j, k; cin >> a >> b; int cond = (a / b + a % b) / b; int sum = a + a / b; while (cond) { cond = (a / b + a % b) / b; sum += cond; a = a / b + a % b; } cout << sum; return 0; }
7
CPP
a, b = map(int, input().split()) new = 0 burnt = a hours = a while burnt >= b: new = burnt//b hours += new burnt = new + burnt%b print(hours)
7
PYTHON3
'''input 3 2 ''' a, b = map(int, input().split()) r = 0 t = 0 while a+r >= b: t += a r += a % b a //= b if r >= b: a, r = a + r//b, r % b print(t+a)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int r; int g(int a, int b) { if (a / b < 1) return 0; r = a % b; return (a / b) + g((a / b) + r, b); } int main() { int a, b; cin >> a >> b; cout << int(a + g(a, b)); }
7
CPP
#include <bits/stdc++.h> int main() { int n, k, x, z, y, t, a, s; scanf("%d %d", &n, &k); s = n; while (n >= k) { s = s + (n / k); n = n / k + n % k; } printf("%d", s); }
7
CPP
n,k=map(int,input().split()) ans=n while n//k>0: ans+=n//k n=n//k+n%k print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int count = 0; count += a; int rem; while (a >= b) { rem = a % b; a /= b; count += a; a += rem; } cout << count << endl; return 0; }
7
CPP
a, b = (int(x) for x in input().split()) n = a + a //(b-1) print((n, n-1)[a%(b-1) < 1])
7
PYTHON3
ar=list(map(int, input().split())) x=ar[0] y=ar[1] ans=(x-1)//(y-1)+x print(ans)
7
PYTHON3
s=input().split(" ") a,b=int(s[0]),int(s[1]) time=0 while a>=b: time+=b a=a-b+1 time+=a print(time)
7
PYTHON3
import math n,m=map(int,input().split()) c=0 c+=n d=0 while(n>=m): c+=math.floor(n/m) d=n n=int(n/m) n=n+d%m print(c)
7
PYTHON3
i,n=map(int,input().split()) candlesLit = 0 while i > 0: i -= 1 candlesLit += 1 if candlesLit % n == 0: i += 1 print(candlesLit)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, rem = 0; cin >> a >> b; c = a; while (a != 0) { rem += a % b; a = a / b; if (rem >= b) { rem -= b; a++; } c += a; } cout << c; return 0; }
7
CPP
import math new_candles, candles_to_new = input().split() new_candles = int(new_candles) candles_to_new = int(candles_to_new) num_hours = new_candles candles_left = new_candles while True: if (candles_left < candles_to_new): break num_hours += candles_left// candles_to_new candles_left = candles_left%candles_to_new + candles_left //candles_to_new print(num_hours)
7
PYTHON3
a,b = map(int,input().split()) t = 0 while a >= b: a -= (b - 1) t += b t += a print (t)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAX = 500 + 7; const int INF = 1e9; int s, k, n, m, x, y, p, q, c, d, a, b, caseno = 0, ans = 0, excess = 0; int MAIN() { cin >> a >> b; while (a > 0) { ans += a; a = a + excess; excess = a % b; a = a / b; } cout << ans; return 0; } int main() { ios_base::sync_with_stdio(false); return MAIN(); }
7
CPP
burning, eff = map(int, input().split()) times = 0 extra = 0 while burning > 0: times += burning tmp = burning+extra extra = (tmp) % eff burning = (tmp-extra) // eff print(times)
7
PYTHON3
# cook your dish here a,b=map(int,input().split()) cnt=a rem=a%b while a>=b: c=a//b a=c+rem cnt+=c rem=a%b print(cnt)
7
PYTHON3
a,b=list(map(int,input().split())) c=0 d=0 while a>=b: c=c+int(a/b)*b a=a-int(a/b)*b+int(a/b) c+=a print(c)
7
PYTHON3
a,b=map(int,input().split()) c=str(a) n=0 t=a for nn in range(500): t=a//b tt=a%b if t==0: break else: n=n+t a=t+tt print(int(c)+n)
7
PYTHON3
abStr = input() a = int(abStr.split()[0]) b = int(abStr.split()[1]) time = 0 while a>=b: a = a-b a = a+1 time = time + b time = time + a print(time)
7
PYTHON3
a,b = input().split() a = int(a) b = int(b) ans=a; r=0 while a>0: r+=a a=r//b r = r%b ans+=(a) print(ans)
7
PYTHON3
a=str(input("")) b=a.split(" ") c=int(b[0]) d=int(b[1]) x=int(c/d) rem=c%d sum1=c while(x>0): sum1=sum1+x rem=rem+(x%d) x=int(x/d) rem1=rem%d if(rem>0): while(rem>0): sum1=sum1+(rem/d) rem1=rem1+(rem%d) rem=int(rem/d) print(int(sum1))
7
PYTHON3
x=input().split() print(((int(x[0])-1)//(int(x[1])-1))+int(x[0]))
7
PYTHON3
a, b = map(int, input().split()) ans = 0 while a > 0: ans += 1 if ans % b: a -= 1 print(ans)
7
PYTHON3
a, b = map(int,input().split()) count = 0 total = a while a >= b: count = a // b total += count a = count + (a % b) if a > b: total += a // b print(total) else: print(total)
7
PYTHON3
a,b=[int(x) for x in input().split()] m,n,c=[a,0,0] while m>0: n+=m m,c=[(m+c)//b,(m+c)%b] print(n)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int hour = a; while (a / b >= 1) { hour += a / b; a = a / b + a % b; } cout << hour; }
7
CPP
#include <bits/stdc++.h> int main() { int a, b; while (scanf("%d%d", &a, &b) == 2) { int ans = 0, tmp = 0; while (a > 0) { ans += a; tmp += a; a = tmp / b; tmp %= b; } printf("%d\n", ans); } return 0; }
7
CPP
a,b=map(int,input().split()) ans=a while(a>=b): c=a//b a=a%b+c ans+=c print(ans)
7
PYTHON3
#!/usr/bin/env python # coding: utf-8 # In[5]: l=input() a,b=l.split() a,b=int(a),int(b) # In[6]: hours=a while a>=b: c=a%b a=a//b hours+=a a+=c # In[7]: print(hours) # In[ ]: # In[ ]: # In[ ]: # In[ ]: # In[ ]: # In[ ]: # In[ ]:
7
PYTHON3
a,b=map(int,input().split()) used=0;hours=0 while a!=0: a+=-1 hours+=1 used+=1 if used==b: a+=1 used=0 print(hours)
7
PYTHON3
l = [int(i) for i in input().split()] a= l[0];b = l[1] c= a//b r = a%b e=c def candles(a,b,c,r,e): while (c>=1): r += c%b c //= b e += c if r<b: return(e) elif r==b: return (e+1) else: return(e+candles(a,b,r//b,r%b,r//b)) if a>=b: d = candles(a,b,c,r,e) print(a+d) else: print(a)
7
PYTHON3
a, b = map(int, input().split()) burnt = 0 hours = a while a >= b: hours += a // b a = a // b + a % b print(hours)
7
PYTHON3
a,b=map(int,input().split()) c,x=a,a while x>=b: c+=(x)//b x=x//b+x%b print(c)
7
PYTHON3
n=[int(i) for i in input().split(" ")] a=n[0] b=n[1] count=0 while a>=b: a=a-b+1 count+=b count+=a print(count)
7
PYTHON3
a,b=[int(x) for x in input().split()] c=0 stubs=0 while a>0: c+=a stubs+=a a=stubs//b stubs=stubs%b print(c)
7
PYTHON3
a, b = map(int, input().split()) duration = 0 remains = 0 while a > 0: duration += a a += remains remains = 0 remains += a % b a //= b print(duration + remains // b)
7
PYTHON3