solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; const int N = 100009; int x, y, n, m, i, u, w, z, sum, best, j, k, t, ans; int a[N], d[N]; int main() { cin >> n >> x; k = n; while (n >= x) { ans += n / x; n = n / x + (n % x); } ans += k; cout << ans; return 0; }
7
CPP
y = [int(i) for i in input().split()] x = y[0] y = y[1] z = 0 a = 0 while x>0: z += 1 x -= 1 a += 1 if a%y==0: x += 1 a = 0 print(z)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T& x) { bool f = false; char ch = getchar(); x = 0; while (ch < 48) f = (ch == '-'), ch = getchar(); while (47 < ch) x = (x << 3) + (x << 1) + ch - 48, ch = getchar(); if (f) x = -x; } int a, b, ans; int main() { read(a), read(b); while (a) { if (a >= b) ans += a / b * b, a = a - a / b * b + a / b; else ans += a, a = 0; } printf("%d\n", ans); return 0; }
7
CPP
t=0 k=0 n,b=map(int,input().split()) while n>0: t+=n n=n+k k=n%b n=n//b print(t)
7
PYTHON3
#ashu@gate22 n,m=map(int,input().split()) ans=n a=(n//m) ans+=a rem=n%m+a while rem>=m: a1=rem//m ans+=a1 rem=rem%m+a1 print(ans)
7
PYTHON3
def f(a,b): return (a-1)//(b-1)+a if __name__ == '__main__': a,b=map(int,input().split()) print(f(a,b))
7
PYTHON3
x=[int(z) for z in input().split()] a=x[0] b=x[1] count = a n=a while n>= b : n=n/b count = count + (n) print(int(count+n/b))
7
PYTHON3
#include <bits/stdc++.h> int main() { int n, m, sum; while (scanf("%d%d", &n, &m) != EOF) { sum = n; while (n / m != 0) { sum = sum + n / m; n = n / m + n % m; } printf("%d\n", sum); } return 0; }
7
CPP
a, b = map(int,input().split()) count_h = a while a >= b: a -= b a += 1 count_h += 1 print(count_h)
7
PYTHON3
a,b=map(int,input().split()) c=0 rem=a while(rem>=b): r=rem%b rem=rem//b c+=rem rem=rem+r print(a+c)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c; cin >> a >> b; c = a; while (a >= b) { long long d = a / b; c += d; long long k = a % b; a = d + k; } cout << c; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c = 0, m, s; cin >> a >> b; c += a; while (a >= b) { s = a / b; m = a % b; c += s; a = s + m; } cout << c; return 0; }
7
CPP
from __future__ import division, print_function from collections import * from math import * from itertools import * from time import time import os import sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip ''' Notes: ''' def main(): a, b = map(int, input().split()) dummy = a overall_hours = a while(True): if dummy >= b: dummy2 = dummy % b dummy //= b overall_hours += dummy dummy += dummy2 else: break print(overall_hours) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main()
7
PYTHON3
a,b=map(int,input().split()) count=a bank=0 while((a+bank)>=b): tmp=a a=(a+bank)//b bank=(tmp+bank)%b count+=a print(count)
7
PYTHON3
a=list(map(int,input().split(' '))) time=0 used=0 while True: time+=a[0] used+=a[0] a[0]=0 if used>=a[1]: a[0]+=int(used/a[1]) used=used%a[1] else: break print(time)
7
PYTHON3
a, b = [int(i) for i in input().split()] c, s, k = 0, a, 0 while s != 0: s -= 1 k += 1 if k == b: s += 1 k = 0 c += 1 print(c)
7
PYTHON3
import sys import math import bisect def main(): ans = 0 r = 0 n, m = map(int, input().split()) while n: ans += n r += n n, r = (r // m, r % m) print(ans) if __name__ == "__main__": main()
7
PYTHON3
a,b=map(int,input().split()) answ = a while a>=b: answ+=a//b a=a//b+a%b print(answ)
7
PYTHON3
c,b = [int(i) for i in input().split()] print((c*b-1)//(b-1))
7
PYTHON3
a, b = list(map(int, input().split())) hours = 0 x = a hours += a while(a >= b): x = a // b hours += x y = a % b a = x + y print(hours)
7
PYTHON3
line = input().split() a = int(line[0]) b = int(line[1]) c = 0 while True: if a >= b: c += b a = a - b + 1 else: c += a break print (c)
7
PYTHON3
candles, b = map(int, input().split()) hours = 0 candle_ends = 0 while candles > 0: candle_ends += candles hours += candles candles, candle_ends = divmod(candle_ends, b) print(hours)
7
PYTHON3
a, b = map(int, input().split()) burnt = 0 t = 0 while a > 0: t += a burnt += a a = burnt//b burnt = burnt % b print(t)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int rem = 0; int hrs = 0; while (a > 0) { hrs += a; rem += a; a = rem / b; rem %= b; } cout << hrs << endl; }
7
CPP
#include <bits/stdc++.h> int main() { int a, b, sum; scanf("%d %d", &a, &b); sum = a; int r = 0; int n = a; while (n > 0) { r = r + n % b; n = n / b; sum = sum + n; } while (r >= b) { n = r; r = 0; while (n > 0) { r = r + n % b; n = n / b; sum = sum + n; } } printf("%d", sum); return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int arr[100] = {0}; int main() { long long int n, m, b = 0; cin >> n >> m; long long int ans = n; while (n >= m) { ans += n / m; b = n % m; n /= m; n += b; } cout << ans << endl; }
7
CPP
n,m=map(int,input().split()) print((n*m-1)//(m-1))
7
PYTHON3
# https://codeforces.com/problemset/problem/379/A a, b = map(int, input().split()) candles = a burnt = 0 while candles >= b: burnt += (candles // b) * b candles = candles % b + candles // b burnt += candles print(burnt)
7
PYTHON3
""" a - candles if (n // m) == m: return 0 elif (n // m) < m: return 1 else: """ def ans(n): if n < 1: return n else: return n + ans(n/m) n, m = map(int, input().split()) print(int(ans(n)))
7
PYTHON3
a, b = map(int, input().split()) cinder = 0 # кол-во потухших в остатке accumulated = a # накопленное while a > 0: new = (cinder + a) // b cinder = (a + cinder - new * b) a = new accumulated += a print(accumulated)
7
PYTHON3
a,b = map(int,input().split()) h = a while a>=1: a = a/b h+=a print(int(h))
7
PYTHON3
l = list(map(int,input().split())) h = 0 a,b = l[0],l[1] while (a>0): a-=1 h+=1 #print ('h',h,'a',a) if (h%b==0): a+=1 print (h)
7
PYTHON3
n , m = map(int, input().split(' ')) print(n + (n - 1) // (m - 1))
7
PYTHON3
#!/usr/bin/env python3 """ CodeForces 379 A. New Year Candles http://codeforces.com/problemset/problem/379/A @author yamaton @date 2015-07-28 """ def solve(candle, b): remaining = 0 cnt = 0 while candle: cnt += candle nxt_candle = (candle + remaining) // b remaining = (candle + remaining) % b candle = nxt_candle return cnt def main(): a, b = [int(i) for i in input().split()] result = solve(a, b) print(result) if __name__ == '__main__': main()
7
PYTHON3
a, b = map(int, input().split()) hours = a while True: c = a // b a = c + (a % b) hours += c if a < b: break print(hours)
7
PYTHON3
a,b = map(int,input().split()) k = 1 while k <= a: if k % b == 0: a += 1 k += 1 print(a)
7
PYTHON3
a,b = map(int,input().split()) sumh = a while a>=1: sumh = sumh + (a / b) a = a / b print(int(sumh))
7
PYTHON3
inp = [int(a) for a in input().strip().split(' ')] candles = inp[0] needed_candles = inp[1] hours = 0 remaining_candles = 0 while candles > 0: hours += candles new_candles = candles // needed_candles remaining_candles += candles % needed_candles if remaining_candles >= needed_candles: new_candles += remaining_candles // needed_candles remaining_candles = remaining_candles % needed_candles candles = new_candles print(hours)
7
PYTHON3
a,b = map(int, input().split()) candles = a while(a>=b): candles += a//b a = a//b + a%b print(candles)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; long long mem[20]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long a, b, cnt = 0; cin >> a >> b; a *= b; a--; b--; a /= b; cout << a << endl; }
7
CPP
a,b=map(int,input().split()) t=0 m=0 while a>0: t+=1 m+=1 a-=1 if m==b: m=0 a+=1 print(t)
7
PYTHON3
a, b = map(int, input().split()) s = a while a // b > 0: s += a // b a = sum(divmod(a, b)) print(s)
7
PYTHON3
#include <bits/stdc++.h> int main() { int a, b, c, d, e; scanf("%d %d", &a, &b); c = a * b; d = c - 1; e = b - 1; printf("%d\n", d / e); }
7
CPP
a,b=input().split() a=int(a) b=int(b) noofhours=a while a>=b: d=a//b; noofhours=noofhours+d a=a//b+a%b print(noofhours)
7
PYTHON3
x,y=map(int,input().split()) c=x k=x while k>=y: if k%y==0: k=k//y c+=k else: i=k%y k=k//y c+=k k+=i print(c)
7
PYTHON3
a, b = map(int, input().split()) ans = a while a >= b: f = a // b ans += f a = a % b + f print(ans)
7
PYTHON3
a, b = [int(x) for x in input().split()] num_whole = a num_ended = 0 ans = 0 while num_whole > 0: ans += num_whole num_ended = num_ended + num_whole num_whole = num_ended // b num_ended = num_ended % b print(ans)
7
PYTHON3
ab=input().split() a=int(ab[0]) b=int(ab[1]) i=a r=0 count=0 while(i>0): count+=i q=i//b r+=i%b if(r//b>0): q+=r//b r%=b i=q print(count)
7
PYTHON3
x,y=[int(i) for i in input().split()] sum=0 while x>0: x=x-1 sum+=1 if sum%y==0: x+=1 print(sum)
7
PYTHON3
inp=[int(i) for i in input().split()] old=0 a=inp[0] b=inp[1] time=0 while a>0: a-=1 old+=1 time+=1 if old>=b: a+=1 old-=b print(time)
7
PYTHON3
s = input().split(' ') candles = int(s[0]) b = int(s[1]) h = 0 left = 0 while(candles > 0): h += candles left += candles candles = left // b left = left % b print(h)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; signed main() { long long a, b; cin >> a >> b; long long dem = 0, du = 0; while (1) { dem += a; du += a % b; a /= b; if (du >= b) { a += 1; du -= b; } if (a == 0 && du < b) { dem += a; break; } } cout << dem; }
7
CPP
line=input().split() a=int(line[0]) b=int(line[1]) n=a m=0 while True: a0=a a=(a0+m)//b if a==0: break n+=a m=(a0+m)%b print(n)
7
PYTHON3
a, b = map(int, input().split()) ans=0 while a>=b: ans += b a= a-b+1 print(ans+a)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int cnt = a; while (a >= b) { cnt += a / b; a = a / b + a % b; } cout << cnt << endl; }
7
CPP
a, b = map(int, input().split()) t = 0 candles = a old = 0 while candles > 0 and old < b: t = t + 1 candles = candles - 1 old = old + 1 if old >= b: old = 0 candles = candles + 1 print(t)
7
PYTHON3
a, b = map(int, input().split()) maxi = a while a >= b: maxi += a//b a -= (a//b)*(b-1) print(maxi)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int sum = a; while (a >= b) { sum += a / b; a = a / b + a % b; } cout << sum; }
7
CPP
a, b = map(int, input().split()) count = a while a // b != 0: count += a // b a = (a // b) + (a % b) print(count)
7
PYTHON3
def main(): s = input() a, b =map(int, s.split()) n = 0 y = 0 while True: n += a t = a + y a = t // b y = t % b if a == 0: break print(n) main()
7
PYTHON3
import re s=input() d=re.findall(r'\d+',s) a=int(d[0]) b=int(d[1]) hours=a col=a while (col%b)+(col//b)>=b: hours=hours+(col//b) col=(col//b)+(col%b) hours=hours+(col//b) print(hours)
7
PYTHON3
temp = input().split() a = int(temp[0]) b = int(temp[1]) h = 0 p = 0 while a > 0: a -= 1 p += 1 if p == b: a += 1; p = 0 h += 1 print(h)
7
PYTHON3
a, b = map(int, input().split()) ans = 0 for i in range(1, a + 1): ans += 1 if ans % b == 0: ans += 1 print(ans)
7
PYTHON3
a, b = map(int,input().split()); print((b*a-1)//(b-1))
7
PYTHON3
a,b=map(int,input().split()) count=rem=0 while a!=0: count+=a rem+=a%b a=a//b if rem>=b: a+=rem//b rem=rem%b print(count)
7
PYTHON3
n,k=[int(i) for i in input().split()] nd=0 r=0 while n>0: nd=nd+n m=(n+r)//k r=(n+r)-(k*m) n=m #print(n,r) print(nd)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, ans = 0; cin >> a >> b; while (a >= b) { ans = ans + (a / b) * b; a = a % b + a / b; } cout << ans + a << endl; return 0; }
7
CPP
n,m=map(int,input().split()) i=0 c=0 ans=n while(n>=m): c=0 while(n>=m): n=n-m c+=1 #print(n,c) n=n+c ans+=c print(ans)
7
PYTHON3
a, b = map(int, input().split()) hours, c = 0, 0 while a > 0: a -= 1 hours += 1 c += 1 if c == b: a += 1 c = 0 print(hours)
7
PYTHON3
a, b = (int(x) for x in input().split()) t = 0 bo = 0 while a > 0: a -= 1 bo += 1 if bo == b: a += 1 bo = 0 t += 1 print(t)
7
PYTHON3
# coding: utf-8 a, b = [int(i) for i in input().split()] aa = 0 cnt = 0 while a: cnt += a temp = a+aa a = temp//b aa = temp%b print(cnt)
7
PYTHON3
a,b = map(int,input().split()) count=0 i = 1 while a != 0: count+=1 if count == i*b: a+=1 i+=1 a-=1 print(count)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; printf("%d", ((a * b - 1) / (b - 1))); return 0; }
7
CPP
n = input() n = n.split() m = int(n[1]) n = int(n[0]) c=0 while n>0: c+=1 n-=1 if(c%m==0): n+=1 print(c)
7
PYTHON3
# https://codeforces.com/problemset/problem/379/A numbers = input() numbers = list(map(int, numbers.split())) a = numbers[0] b = numbers[1] candles = a answer = 0 while candles>=b: answer+= (candles//b)*b newCandles = candles//b newCandles+=candles%b candles = newCandles print(answer+candles)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(const T &a) { return a * a; } int a, b, x, ans; int main() { scanf("%d%d", &a, &b); while (1) { ans += a; x += a; if (x / b == 0) break; a = x / b; x -= (x / b) * b; } printf("%d\n", ans); }
7
CPP
n, m = list(map(int, input().split())) ans = 0 sr = 0 used = 0 new = n while True: ans = ans + new used = new + sr if used < m: break new = used // m sr = used % m print(ans)
7
PYTHON3
n,m = input().split() n,m = int(n),int(m) ans = n while n >= m: value = int(n/m) n = int(n/m) + int(n % m) ans += value print(ans)
7
PYTHON3
n,m=map(int,input().split()) day=0 while n>0: day+=1 if day%m==0: n+=1 else: n=n n-=1 else: print(day)
7
PYTHON3
s = input().split() a, b = int(s[0]), int(s[1]) ans = 0 went = 0 while True: a -= 1 ans += 1 went += 1 if went >= b: went -= b a += 1 if a == 0: break print(ans)
7
PYTHON3
def qc(n,b): t,z=0,0 while n>0: t+=n n=t//b-z z+=n return t n,b=[int(x) for x in input().split()] print(qc(n,b))
7
PYTHON3
#include <bits/stdc++.h> int main() { int a, b; scanf("%d%d", &a, &b); int sum = 0, c; sum = a; while (1) { c = a / b; a = c + (a % b); sum += c; if (a < b) break; } printf("%d\n", sum); }
7
CPP
from collections import deque from collections import OrderedDict import math import sys import os import threading import bisect import operator import heapq from atexit import register from io import BytesIO #sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size)) #sys.stdout = BytesIO() #register(lambda: os.write(1, sys.stdout.getvalue())) import io #input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline #sys.stdin = open("F:\PY\\test.txt", "r") input = lambda: sys.stdin.readline().rstrip("\r\n") #input = sys.stdin.readline n, m = map(int, input().split()) answer = n rem = 0 while(n+rem>=m): temp = (n+rem) n=(n+rem)//m rem = temp%m answer+=n print(answer)
7
PYTHON3
m,n = map(int, input().split()) count = m while(m>=n): temp = m//n + m%n count += m//n m = temp print(count)
7
PYTHON3
a,b=list(map(int,input().split())) s,n,g=0,a,a while g!=0: s+=int(n/b) g=int(n/b) n=g+(n%b) print(a+s)
7
PYTHON3
Datos=input() Datos=Datos.split() a=int(Datos[0]) b=int(Datos[1]) hora=0 cont=0 while a>=b: if a%b==0: hora+=a a=a//b else: cont+=a%b hora+=a a=a//b if cont>=b: a+=1 cont=cont%b hora+=a if a+cont>=b: hora+=1 print(hora)
7
PYTHON3
a,b=map(int,input().split()) candles=a while (a//b>0): candles += a//b a=a//b+a%b print (candles)
7
PYTHON3
a,b = (int(i) for i in input().split()) s = 0 s1 = a s2 = 0 while (a>0): s+=1 a-=1 if (a==0): s2 = s1%b s1 //=b a+=s1 s1 = a + s2 print(s)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, t = 0; cin >> a >> b; t += a; while (a >= b) { t += (a / b); a = a / b + (a % b); } cout << t; return 0; }
7
CPP
a,b = map(int,input().split()) mas = [] for i in range(a): mas.append(1) if len(mas)%b==0: mas.append(1) print(len(mas))
7
PYTHON3
import sys a, b = map(int, sys.stdin.readline().split()) hour = 0 wentout = 0 while a > 0: hour += a wentout += a if wentout >= b: a = int(wentout / b) wentout -= a*b else: break print(hour)
7
PYTHON3
a,b=map(int,input().split()) x = a // b i = 0 s = a while x >= 1 : i = i + x s = x + s - x * b x = s // b print(a + i)
7
PYTHON3
a, b = map(int, input().split()) e = a while a >= b: e += a//b a = a//b + a%b print(e)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, m, s; cin >> n >> m; cout << n + (n - 1) / (m - 1); return 0; }
7
CPP
a,b = list(map(int, input().split())) s = 0 x = 0 while a != 0: while a > 0: x += (a%b) s += a a = a//b a = x//b x = x%b print(s)
7
PYTHON3
n, k = map(int, input().split()) ans = n r = 0 while(n > 0): n = n + r r = n % k n = n // k ans = ans + n print(ans)
7
PYTHON3
a, b = [int(i) for i in input().split(" ")] hours = a; initial_candles = a while(hours // b - (hours - initial_candles) > 0): hours += hours // b - (hours - initial_candles) print(hours)
7
PYTHON3
i = input() li = list(i.split(" ")) a = int(li[0]) b = int(li[1]) c = int(0) d = int(0) e = int(0) e = a while(True): if(e==0): break else: c = c + e e = (a//b) d = (a % b) a = e + d print(c)
7
PYTHON3
s = str(input()).split() a = int(s[0]) b = int(s[1]) c = 0 t = 0 while a > 0: a -= 1 c += 1 if c == b: a += 1 c = 0 t += 1 print(t)
7
PYTHON3
a,b = input().split(' ') a = int(a) b = int(b) count = 0 r = 0 while a>0 : count += a r += a a = int(r/b) r = r%b print(count)
7
PYTHON3