solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
a , b = input().split() a = int(a) b = int(b) n = a k = 0 ans = 0 while n != 0: n -=1 k +=1 if k == b: k = 0 n +=1 ans +=1 print(ans)
7
PYTHON3
ans = 0 leftover = 0 [a, b] = list(map(int, input().split())) while(a): ans += a leftover += a a = int(leftover / b) leftover %= b print(ans, end = '')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int x = a; long int sum = 0; int res = 0; sum = a - (a % b); res = a % b + (a / b); while (res >= b) { sum += res - (res % b); res = res / b + res % b; } sum += res; cout << sum; return 0; }
7
CPP
a, b = map(int, input().split()) k = a x = 0 count = 0 while k > 0: k -= 1 x += 1 if x == b: x = 0 k += 1 count += 1 print(count)
7
PYTHON3
#include <bits/stdc++.h> int a, b, s = 0; int main() { scanf("%d %d", &a, &b); if (a - b < 0) printf("%d", a); else { while (a - b >= 0) { s = s + b; a = a - b + 1; } if (a == 1) printf("%d", s + 1); else printf("%d", s + a); } }
7
CPP
a,b = map(int,input().split()) ogarki=0 svechi=a count=0 while svechi>0: svechi-=1 ogarki+=1 if ogarki==b: svechi+=1 ogarki-=b count+=1 print(count)
7
PYTHON3
n, k = map(int, input().split()) res = n while n>=k: res += (n//k) n = n//k + n%k print(res)
7
PYTHON3
a,b = map(int,input().split(' ')) print(int((int(a*b-1))/(int(b-1))))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int a, b; cin >> a >> b; long long int ans = a, tem = a / b, tem2 = a % b, tem3 = tem; while (tem > 0) { ans += tem; tem3 = (tem3 + tem2) / b; if (tem + tem2 < b) { tem2 = 0; } else { tem2 = (tem + tem2) % b; } tem = tem3; } cout << ans << "\n"; return 0; }
7
CPP
n, m = map(int, input().split()) chas = 0 while n > 0: chas += 1 n -= 1 if chas % m == 0: n += 1 print(chas)
7
PYTHON3
a, b = map(int, input().split()) t = 0 prev = 0 # количество не задействованных огарков, оставшихся с предыдущих итераций while a != 0: t += a # текущее кол-во свечей (ждём, когда догорят все) a, prev = (a + prev) // b, (a + prev) % b # кол-во новых свечей, сделанных из текущих огарков print(t)
7
PYTHON3
# New Year Candles def candles(a, b): ans = 0 while a >= b: ans += b a -= b a += 1 return ans + a a, b = list(map(int, input().rstrip().split())) print(candles(a, b))
7
PYTHON3
a,b = [int(i) for i in input().split()] def calc(a,b,count = 0) : if a<b and a>=0: count += a return count elif a>=0: return calc(a-b +1, b,count) + b print(calc(a, b,count = 0))
7
PYTHON3
n, m = input().split() n, m = int(n), int(m) ans = 0 k = 0 while n > 0: ans += n newk = (n + k) % m newn = (n + k) // m k = newk n = newn print(ans)
7
PYTHON3
a,b = list(map(int, input().split(" "))) x,sum=a,0 while a>=b: sum+=a//b a=(a//b)+(a%b) print(sum+x)
7
PYTHON3
n,t=map(int,input().split()) tt=0 while n>=t: n=n-t+1 tt+=1 print((tt*t)+n)
7
PYTHON3
a,b=[int(i) for i in input().split()] k=a while True: p=a%b a=a//b if a==0: break k=k+a a=a+p print(k)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; const int MINF = 0x80000000; const long long mod = 1000000007; const int cons = 100001; int main() { int a, b; cin >> a >> b; int ans = a; int tmp; int tm; while (1) { tmp = a / b; if (!tmp) break; tm = a % b; ans += tmp; a = tmp + tm; } cout << ans << endl; return 0; }
7
CPP
from sys import stdin,stdout from collections import * st=lambda:list(stdin.readline().strip()) li=lambda:list(map(int,stdin.readline().split())) mp=lambda:map(int,stdin.readline().split()) inp=lambda:int(stdin.readline()) pr=lambda n: stdout.write(str(n)+"\n") mod=1000000007 INF= float('inf') def solve(): a,b = mp() ans=a while a>=b: a-=b ans+=1 a+=1 pr(ans) for _ in range(1): solve()
7
PYTHON3
thing = input() thing = thing.split(" ") a=int(thing[0]) b=int(thing[1]) time = 0 newCandles = a oldCandles = 0 while oldCandles >= b or newCandles > 0: time += newCandles oldCandles += newCandles newCandles = int(oldCandles/b) oldCandles -= b*int(oldCandles/b) print (time)
7
PYTHON3
a,b=map(int,input().split()) tot=a while a>=b: tot=tot+int(a/b) x=a%b a=int(a/b) a=a+x print(int(tot))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int rez = 0; int count = a; while (a >= b) { if (a % b == 0) { count += a / b; a = a / b; } else { count += a / b; a = a / b + a % b; } } cout << count; return 0; }
7
CPP
n,k=map(int,input().split()) c=n while(n//k): c+=n//k n=n//k+n%k print(c)
7
PYTHON3
from collections import deque, Counter, OrderedDict from heapq import nsmallest, nlargest from math import ceil,floor,log,log2,sqrt def binNumber(n,size=1): return bin(n)[2:].zfill(size) def gcd(a,b): if a == 0: return b return gcd(b%a,a) def iar(): return list(map(int,input().split())) def ini(): return int(input()) def isp(): return map(int,input().split()) def sti(): return str(input()) # ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code if __name__ == "__main__": a,b = isp() k = a rem = 0 while a != 0: rem += a%b if rem >= b: #k += 1 rem -= b a = a//b + 1 else: a = a//b k += a print(k)
7
PYTHON3
n,m=map(int,input().split()) h=n while n>=m: d= n // m h += d x=n % m n=d + x print(h)
7
PYTHON3
a,b=[int(i) for i in input().split()] n=a x=a y=0 for i in range(2000): z=x+y x=z//b y=z%b if x==0: break else: n+=x print(n)
7
PYTHON3
a, b = map(int, input().split()) total_hours = a candles_out = a while candles_out >= b: candles_out += 1 - b total_hours += 1 print(total_hours)
7
PYTHON3
a,b = map(int,input().split()) used = 0 count = 0 while a: a -= 1 used += 1 count += 1 if used == b: a += 1 used = 0 print(count)
7
PYTHON3
from collections import Counter n, k = list(map(lambda x: int(x),input().split())) cnt = n while(n>0): temp_ = int(n/k) n = temp_ + n%k cnt+=temp_ if n<k: break print(cnt)
7
PYTHON3
m,n=map(int,input().split()) print((m*n-1)//(n-1))
7
PYTHON3
a, b = [int(x) for x in input().split()] i = 1 while i<=a: if (i%b)==0: a+=1 i+=1 print(a)
7
PYTHON3
n,t=map(int,input().split()) day=1 while n>0: if day%t==0: n+=1 day+=1 n-=1 print(day-1)
7
PYTHON3
X,Y = input().split() x = int(X) y = int(Y) candles = x while x >= y : new = x // y reserve = x - (new*y) x = new + reserve candles = candles + new print(candles)
7
PYTHON3
a, b = map(int, input().split()) print((a - 1) // (b - 1) + a)
7
PYTHON3
import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1]))#might need to remove the -1 def invr(): return(map(int,input().split())) h = 0 a, b = invr() while True: if a >= b: a -= b-1 h += b else: h += a break print(h)
7
PYTHON3
a,b = map(int,input().split()) h = a while a>=b: h+=int(a/b) a = int(a/b)+int(a%b) print(h)
7
PYTHON3
from sys import stdin, stdout def solve(a, b): result = 0 old = 0 while a != 0: result += a neww = (a + old) // b old = (a + old) % b a = neww return result if __name__ == '__main__': s = stdin.readline() (a, b) = s.split(' ') a = int(a) b = int(b) result = solve(a, b) print(result) # a = int(a) # b = int(b) # result = solve(a, b) # print(result)
7
PYTHON3
a,b=map(int,input().split()) c=0 ans=0 burned=0 ans += a burned += a while burned//b!=0: ans += burned//b burned = burned%b+burned//b print(ans)
7
PYTHON3
a, b = map(int, input().split()) candel = a while a >= b: candel += a // b a = a % b + a // b print(candel)
7
PYTHON3
a,b=map(int,input().split()) ans=0 ans+=a c,d=0,0 while a>=b: c=a//b ans+=c a=c+(a%b) print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int f(int a, int b) { int l = 0, t = 0; while (1) { t += a; l += a % b; a /= b; a += l / b; l %= b; if (a == 0) return t; } } int main() { int a, b; cin >> a >> b; cout << f(a, b) << endl; return 0; }
7
CPP
a, b = map ( int, input().split() ) chasov=0 b1=b while a>0: a=a-1 chasov=chasov+1 if chasov==b1: a=a+1 b1=b1+b print(chasov)
7
PYTHON3
a,b=map(int,input().split()) res=a ost=0 while True: res+=a//b a=a//b+a%b if a<b: break print(res)
7
PYTHON3
# A. Новогодние свечки n, m = map(int, input().split()) i = 1 while n >= m * i: n += 1 i += 1 print(n)
7
PYTHON3
a,b=map(int,input().split()) ans=a while(a>=b): ans+=a//b a=a//b+a%b print(ans)
7
PYTHON3
from math import floor x =input().split() a =int(x[0]) b =int(x[1]) hours = 0 unused =.01 used = a while used>=1: hours+=used cache = used//b unused =unused+(used%b)/b used = cache+floor(unused) unused= unused-floor(unused) print(hours)
7
PYTHON3
a,b = map(int,input().split()) t=a rem=0 while a/b!=0: new=int(a/b) rem=rem+a%b if rem/b>=1: a=new+int(rem/b) rem=rem%b else: a=new t=t+a print(t)
7
PYTHON3
a, b = map(int, input().split()) print(a + ~-a // ~-b)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; void func() { int a, b; cin >> a >> b; int c = a, ost = 0; while (a) { ost += a; a = ost / b; ost = ost % b; c += a; } cout << c; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; while (t--) { func(); } return 0; }
7
CPP
def func(START,D,REM,ANS): if (START<D and START+REM<D): return ANS elif (START>=D): while START>=D: REM+=(START%D) START//=D ANS+=START REM+=(START%D) return func(REM,D,0,ANS) else: START+=REM REM=0 while START>=D: REM+=(START%D) START//=D ANS+=START REM+=(START%D) return func(REM,D,0,ANS) C,D=map(int,input().split()) REM=C%D START=C//D ANS=C+START print(func(START,D,REM,ANS))
7
PYTHON3
n, k = input().split() n = int(n) k = int(k) count = n while(n >= k): temp = n//k + n%k count += n//k n = temp print(count)
7
PYTHON3
a, b = input().split() a = int(a) b = int(b) ans1 = (a*b)-1 ans2 = b - 1 ans = int(ans1/ans2) print(ans)
7
PYTHON3
a, b = tuple(map(int, input().split())) spent = a hours = a while spent >= b: spent -= b hours += 1 spent += 1 print(hours)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int A, B; cin >> A >> B; int Temp = A; for (int i = 1; i <= A; ++i) { if (i % B == 0) { A++; } } cout << A << endl; return 0; }
7
CPP
a,b=map(int,input ("").split()) print(a+((a-1)//(b-1)))
7
PYTHON3
l=input().split() a=int(l[0]) b=int(l[1]) t=0 s=a while (a+t)/b>=1: s+=int(a/b) a=int(a/b+a%b) print(s)
7
PYTHON3
x=input() x=x.split() candles=int(x[0]) temp=candles re=int(x[1]) flag=0 while candles>=re: candles=candles-re candles=candles+1 flag=flag+1 print(temp+flag)
7
PYTHON3
def main(): a, b = list(map(int, input().split())) light_out = 0 total_time = 0 while a > 0: total_time += 1 a -= 1 light_out += 1 if light_out == b: light_out = 0 a += 1 print(total_time) if __name__ == "__main__": main()
7
PYTHON3
from sys import stdin input = stdin.readline def candle(a, b, c = 0): t = a while a >= b: while a: c += a % b a //= b t += a a = c c = 0 return t print(candle(*map(int, input().split())))
7
PYTHON3
#Candles c = 0 a, b = map(int, input().split()) hours = a while True: if a < b: break hours += a // b a = a // b + a % b print(hours)
7
PYTHON3
a, b = map(int, input().split()) ans = 0 tt = a while a >= b: m = a // b ans += m t = a % b a = m + t print(ans + tt)
7
PYTHON3
#a = input() #b = input() a, b = input().split() a = int(a) b = int(b) def new(x): if(x<b): return 0 else: count = int(x/b) + new(int(x/b) + x%b) return count count = a + new(a) print(int(count))
7
PYTHON3
n, m = map(int, input().split()) a, b, c, r = 1, n + 1, 0, 0 while b - a > 0: for i in range(a, b): if i % m == 0: c += 1 a, b = n + r + 1, n + c + r + 1 r += c c = 0 if (n + r) % m == 0: r += 1 print(n + r)
7
PYTHON3
a, b = map(int, input().split()) c = a while a // b: c += a // b a = a//b + a % b print(c)
7
PYTHON3
row = str(input()).split(' ') n=int(row[0]) r=int(row[1]) aux=0 usadas=n recicladas=n/r while(recicladas>1): usadas+=int(recicladas) aux=float(str(recicladas-int(recicladas))[1:]) recicladas=int(recicladas)/r recicladas+=aux if(recicladas==1.0): usadas+=1 print (usadas)
7
PYTHON3
# For taking integer inputs. import math def inp(): return(int(input())) # For taking List inputs. def inlist(): return(list(map(int, input().split()))) # For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable. def instr(): s = input() return(list(s[:len(s)])) # For taking space seperated integer variable inputs. def invr(): return(map(int, input().split())) a, b = invr() hr = a hate = 0 pora = a while True: new_candle = pora // b hate = pora % b hr += new_candle pora = new_candle + hate if pora < b: break print(hr)
7
PYTHON3
a, b = map(int, input().split()) n = a p = a y = 0 while n > b: x = n // b p += x n = x + n % b print(p + n // b)
7
PYTHON3
n,m=map(int,input().split()) a=(n*m-1)//(m-1) print(a)
7
PYTHON3
m,n = map(int, input().split());print(m + (m-1)//(n-1))
7
PYTHON3
a, b = map(int, input().split()) ans = 0 s = 0 while(a > 0): a -= 1 s += 1 if(s == b): s = 0 a += 1 ans += 1 print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int a, b; cin >> a >> b; int cnt = 0; int dead = 0; while (a) { cnt += a; dead += a; a = dead / b; dead = dead % b; } cout << cnt << '\n'; return 0; }
7
CPP
if __name__ == "__main__": a, b = map(int, input().split()) ans = a while a // b > 0: ans += a // b a = a // b + a % b print(ans)
7
PYTHON3
candl, new_candl = map(int, input().split()) result = candl bad_candls = candl candl = 0 while True: if bad_candls % new_candl == 0: candl = int(bad_candls / new_candl) bad_candls = 0 else: candl = int(bad_candls / new_candl) bad_candls = bad_candls % new_candl result += candl bad_candls += candl candl = 0 if bad_candls < new_candl: break print(result)
7
PYTHON3
s = input() s1 = s.split(' ') a = int(s1[0]) b = int(s1[1]) day = 0 while a != 0: a = a - 1 day += 1 if day % b == 1: day += 1 print(day - 1)
7
PYTHON3
a, b = list(map(int, input().split())) hours = a while a != 1: if a % b == 0: hours += a // b a //= b elif a > b and a % b != 0: hours += a // b a = a // b + a % b elif a < b: break print(hours)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, res = 0; cin >> a >> b; res = a + a / b; for (int i = a + 1; i <= res; i++) { res += i % b == 0; } cout << res; }
7
CPP
a,b=map(int,input().split(" ")) x = 0 while a>0.1: x+=a a = a/b pass print (int(x))
7
PYTHON3
def func(n): count = 0 while n[0] != count: count += 1 if count % n[1] == 0: n[0] += 1 print(count) n = list(map(int,input().split())) func(n)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, i; cin >> a >> b; int c = a; while (a >= b) { c++; a++; a = a - b; } i++; cout << c; return 0; }
7
CPP
__author__ = "runekri3" a, b = list(map(int, input().split())) candles = a burnt_candles = 0 total_hours = 0 while 1: remakeable_candles = int(burnt_candles / b) candles += remakeable_candles burnt_candles -= remakeable_candles * b if candles <= 0: break total_hours += candles burnt_candles += candles candles = 0 print(total_hours)
7
PYTHON3
a,b = map(int, input().split()) result = 0 left = a*b while left>=b: result += left//b left = left%b+left//b print(result)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int r, n, b, total; cin >> n >> b; total = n; while (n >= b) { total += n / b; r = n % b; n = n / b + r; } cout << total; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int a, b, new_candle, total, remain; while (cin >> a >> b) { total = remain = 0; new_candle = a / b; if (new_candle > 0) { total = a; while (a >= b) { new_candle = a / b; remain = a % b; total = total + new_candle; a = new_candle + remain; } } else total = a + new_candle; cout << total << endl; } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int a, b, un, u, t = 0; cin >> a >> b; t = a; u = a; un = 0; do { un = u / b; t = t + un; u = u % b + un; } while (u > b); un = u / b; t = t + un; cout << t; return 0; }
7
CPP
a,b = list(map(int,input().strip().split(' '))) currc = a rem = 0 ans = 0 while 1: ans += currc rem += currc currc = 0 if rem >= b: currc += rem//b rem = rem % b else: break print(ans)
7
PYTHON3
a,b = map(int,input().split()) #1 1 1 1...b 1 1 1 1...b 1 1 1...b 1 1 1....b ......(a<b)1.....(a) #no of new candles = a//b #new total = a%b + no of new candles count = 0 while (a>0): if a>=b: count += (a//b)*b a = a//b + a%b else: count+=a a=0 print(count)
7
PYTHON3
a,b = map(int,input().split()) time = a num = 0 while True and a > 0: num += a % b a = a // b if num >= b: num -= b a += 1 time += a print(time)
7
PYTHON3
a,b=map(int,input().split()) ans=a rem=0 if b==0: print(a) exit(0) while a//b: rem=a%b ans+=a//b a=(a//b) + rem print(ans)
7
PYTHON3
a,b = map(int,input().split()) c = 0 while(a >= b): a -= b - 1 c += b print(c + a)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c = 0; cin >> a >> b; for (; a; a--, c++, c % b ? 0 : a++) ; return cout << c, 0; }
7
CPP
x=input() x=x.split() x1=int(x[0]) x3=x1 x2=int(x[1]) flag=0 while x1>=x2: x1=x1-x2+1 flag+=1 print(flag+x3)
7
PYTHON3
a, b = [int(x) for x in input().split(' ')] t, r = 0, 0 while a: t += a n = (r + a) // b r = (r + a) % b a = n print(t)
7
PYTHON3
a, b = map(int, input().split()) hours = a +(a-1)//(b-1) print(hours)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b; int count = 0; cin >> a >> b; while (a != 0) { count++; a--; if (count % b == 0) { a++; } } cout << count << endl; }
7
CPP
k=input().split() a=int(k[0]) b=int(k[1]) noc=0 k=0 while a>0: noc+=a k+=a%b #print(k,noc) a=a//b while k>0: noc+=k//b if k>b: k=k%b+k//b else: k=k//b #print(noc,k) print(noc)
7
PYTHON3
# -*- coding: utf-8 -*- """ Created on Thu Jan 30 17:44:37 2020 @author: Zheng Jiajia """ a,b=map(int,input().split()) hour=a while a//b>0: hour+=a//b a=a//b+a%b print(hour)
7
PYTHON3
a, b = map(int, input().split()) z = 0 out = 0 while a!=0: out+=a z, a = (a+z)%b, (a+z)//b print(out)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int a, b, count = 0; cin >> a >> b; int ans = a, rem = a; while (1) { a = ans / b; ans = (ans - a * b); ans += a; rem += a; if (a <= 0) break; } cout << rem << endl; return 0; }
7
CPP
num = input() arr = [] count = 0 for i in range(0,len(num)): if num[i] == ' ': arr.append(int(num[count:i])) count = i+1 elif i == len(num)-1: arr.append(int(num[count:len(num)])) finished = None count = 0 using = arr[0] dead = 0 while finished == None: if using == 0 and dead < arr[1]: break elif using > 0: using -= 1 dead += 1 count += 1 else : using = int(dead/arr[1]) dead = dead%arr[1] print(count) #4 2
7
PYTHON3
a,b=map(int,input().split()) total=a while((a//b)!=0): if(a%b==0): total+=a//b a=a//b else: total+=a//b a=(a//b)+(a%b) print(total)
7
PYTHON3