text
stringlengths 49
983k
|
|---|
#include <bits/stdc++.h>
int main() {
int a, b, sum = 0;
scanf("%d %d", &a, &b);
getchar();
sum = a;
while (b <= a) {
sum += (a / b);
a = (a / b) + (a % b);
}
printf("%d\n", sum);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, n, c = 0;
cin >> a >> b;
n = a;
while (a >= b) {
c = a % b;
a /= b;
n += a;
a += c;
}
cout << n;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int d = 0;
while (a != 0) {
a--;
d++;
if (d % b == 0) {
d++;
}
}
cout << d;
}
|
#include <bits/stdc++.h>
using namespace std;
struct team {
int ans;
bool ok;
};
long long n, cnt = 0, m, q;
string p, s;
inline bool check(long long& n) {
long long t = (long long)sqrt((long double)n);
if (t * t != n) return false;
n = t;
if (n == 2)
return true;
else if (n < 2 || n % 2 == 0)
return false;
t = (long long)sqrt((long double)n);
for (long long i = 3; i <= t; i += 2)
if (n % i == 0) return false;
return true;
}
inline void doing() {
cin >> m >> n;
cnt += m;
while (m >= n) {
cnt += m / n;
m = m % n + m / n;
}
cout << cnt;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
doing();
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
const int N = 81;
const int delta = 10453;
long long n, a[maxn], c, p;
int main() {
cin >> n >> p;
for (int i = 1; i <= n; i++) {
if (i % p == 0) n++;
}
cout << n;
}
|
#include <bits/stdc++.h>
int main() {
int a, b, d, m;
scanf("%d %d", &a, &b);
int res = a;
while (a >= b) {
d = a / b;
res += d;
m = a % b;
a = d + m;
}
printf("%d", res);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int a, b, ans = 0, cnt = 0;
cin >> a >> b;
while (a > 0) {
ans += a;
a += cnt;
cnt = a % b;
a /= b;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, rem;
int main() {
cin >> n >> m;
rem = cnt = n;
while (rem >= m) {
rem -= m;
cnt++;
rem++;
}
cout << cnt;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, b, hr;
cin >> n >> b;
hr = n;
while (n >= b) {
int c = n % b;
n = n / b;
hr = hr + n;
n = n + c;
}
cout << hr << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, ans = 0, var = 0;
cin >> a >> b;
while (a > 0) {
ans += a;
var += a % b;
a /= b;
if (var >= b) {
a += var / b;
var -= b * (var / b);
}
}
cout << ans << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, s = 0;
cin >> n >> k;
while (n >= k) s += n / k * k, n = n % k + n / k;
cout << s + n;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int candle, abmged_days, counter = 0;
cin >> candle >> abmged_days;
while (candle--) {
counter++;
if (counter % abmged_days == 0) {
candle++;
}
}
cout << counter << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long fpow(long long x, long long y, long long p = 1000000007) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) {
y--;
res *= x;
res = res % p;
}
x = x * x;
x = x % p;
y >>= 1;
}
return res;
}
int main() {
ios::sync_with_stdio(0);
long long n, m;
cin >> n >> m;
long long ans = n;
while (1) {
if (n >= m) {
n -= m;
n += 1;
ans++;
} else
break;
}
cout << ans << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, i, j, k, sum = 0;
cin >> a >> b;
if (a < b)
sum = a;
else if (a == b)
sum = a + 1;
else {
sum = a;
int x = 0;
while (a >= b) {
sum = sum + (a / b);
x = a % b;
a = a / b + x;
}
}
cout << sum;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%d", (a * b - 1) / (b - 1));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c = 0, i, s = 0;
cin >> a >> b;
for (i = 1; i <= 2000; i++) {
a--;
c++;
if (c == b) {
a++;
c = 0;
}
if (a == 0) break;
}
cout << i;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, count = 0, ans = 0;
cin >> a >> b;
for (int i = 1; i <= a; i++) {
count++;
ans++;
if (count == b) {
count = 0;
i--;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int a, b, resp, recu;
scanf("%d", &a);
scanf("%d", &b);
resp = a;
while (a != 0) {
if ((a % b) == 0) {
a = a / b;
resp = resp + a;
} else {
recu = a % b;
a = a - recu;
a = a / b;
resp = resp + a;
a = a + recu;
}
if (a < b) {
a = 0;
}
}
printf("%d", resp);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int ctr = a;
int rem = 0;
while (1) {
if (a < b) break;
rem = a % b;
a = a / b;
ctr = ctr + a;
a = a + rem;
}
cout << ctr << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, i, j, hour;
cin >> a >> b;
hour = a;
while (a >= 1) {
a = a / b;
hour = hour + a;
}
int ans = hour;
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, sum, c;
while (cin >> a >> b) {
sum = a;
while (b <= a) {
c = a / b;
sum += c;
a = c + (a % b);
}
cout << sum << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a, b;
cin >> a >> b;
int sum = a;
int rem = 0;
while (a >= b) {
sum += a / b;
rem = a % b;
a /= b;
a += rem;
}
cout << sum << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> v;
int main() {
cin >> n >> m;
v.resize(n);
for (int i = 0; i < v.size(); i++) {
if (i % m == 0) {
v.push_back(0);
}
}
cout << v.size() - 1;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int x, y;
scanf("%d %d", &x, &y);
printf("%d", (x * y - 1) / (y - 1));
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, so;
cin >> a >> b;
long long int sum = a;
so = a;
for (; so >= b;) {
sum += (so / b);
so = (so / b) + (so % b);
}
cout << sum;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, arr[100], count = 0, c;
cin >> n >> x;
count += n;
while (n >= x) {
count += n / x;
n = n / x + n % x;
}
cout << count << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, a = 0, z = 0;
cin >> x >> y;
z += x;
while (x) {
if (x >= y) {
z += x / y;
x = x / y + x % y;
} else {
break;
}
}
cout << z;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
float a, b, flag, sum1 = 0, neew = 0;
int sum = 0;
cin >> a >> b;
flag = a;
while (flag > 0.1) {
sum1 = sum1 + flag;
flag = flag / b;
}
sum = sum1;
cout << sum;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int result = a;
int temp = 0;
while ((a + temp) >= b) {
int t1 = temp;
result += (a + temp) / b;
temp = (a + temp) % b;
a = (a + t1) / b;
}
cout << result << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int hr = a;
while (a >= b) {
hr += a / b;
a = a / b + a % b;
}
cout << hr;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
long long int ans = a;
while (a >= b) {
ans += (a / b);
a = (a / b) + (a % b);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, consumed = 0, time = 0;
cin >> a >> b;
while (a != 0) {
a = a - 1;
consumed++;
time++;
if (consumed == b) {
a++;
consumed = 0;
}
}
cout << time << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
while (cin >> a >> b) {
int ex = 0, ans = 0;
while (true) {
ans += a;
a += ex;
ex = a % b;
a /= b;
if (a == 0 && ex < b) break;
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a + ((a - 1) / (b - 1)) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
long long t = a, k = 0;
while (a >= b) {
k = a % b;
a = a / b;
t += a;
a += k;
}
cout << t;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, k, x, sum = 0;
while (scanf("%d%d", &n, &k) == 2) {
sum = n;
while (n >= k) {
x = n / k;
n = x + n % k;
sum += x;
}
printf("%d\n", sum);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int y, z, n, m, h;
cin >> n >> m;
h = n;
while (1) {
y = n % m;
z = n / m;
h += z;
z += y;
n = z;
if (z < m) cout << h, exit(0);
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int c = 0;
while (n != 0) {
++c;
n--;
if (c % m == 0) n++;
}
cout << c;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << (a * b - 1) / (b - 1);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int ans = a;
while (a >= b) {
int tmp = 0;
if (a % b != 0) tmp = a % b;
a /= b;
ans += a;
a += tmp;
}
cout << ans;
}
|
#include <bits/stdc++.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
int tot = a;
int temp = 0;
while (a / b) {
tot += (a / b);
temp = a % b;
a = (a / b) + temp;
}
printf("%d\n", tot);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int arr[1000003];
int maximo[1000004];
int bonus[1000006];
int marca[100000];
void solve() {
int a, b;
cin >> a >> b;
int sum = a + (a / b);
int cuantos = a / b + (a % b);
while (cuantos >= b) {
sum += cuantos / b;
cuantos = cuantos / b + (cuantos % b);
}
cout << sum << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rang(
chrono::high_resolution_clock::now().time_since_epoch().count());
int mpow(int base, int exp);
template <class T>
T npow(T base, T exp);
const int mod = 1e9 + 7;
const int N = 3e5, M = N;
void Solve_main() {
int i, j, n, m, k;
cin >> n >> m;
int res = n;
while (n >= m) {
res += (n / m);
n = n / m + n % m;
}
cout << res << '\n';
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
int t = 1;
while (t--) {
Solve_main();
}
return 0;
}
int mpow(int base, int exp) {
base %= mod;
int result = 1;
while (exp > 0) {
if (exp & 1) result = ((long long)result * base) % mod;
base = ((long long)base * base) % mod;
exp >>= 1;
}
return result;
}
template <class T>
T npow(T base, T exp) {
T result = 1;
while (exp > 0) {
if (exp & 1) result = (result * base);
base = (base * base);
exp >>= 1;
}
return result;
}
|
#include <bits/stdc++.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
int fc, uc, df, sum = 0;
fc = a;
uc = 0;
df = b;
while (1) {
sum += fc;
if (fc == 0 && uc < df) break;
uc += fc;
fc = uc / df;
uc = uc % df;
}
printf("%d\n", sum);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b;
cin >> a >> b;
long long int res = a, temp;
while (a >= b) {
res += (a / b);
a = a / b + a % b;
}
cout << res << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, rem = 0, rem1 = 0;
cin >> a >> b;
int count = a;
while ((a + rem) >= b) {
rem1 = rem;
count = count + (a + rem1) / b;
rem = (a + rem1) % b;
a = (a + rem1) / b;
}
cout << count;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int ans = 0, rem = 0;
while (a > 0) {
ans += a;
rem += a;
a = rem / b;
rem %= b;
}
cout << ans << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, t = 0, n = 0;
cin >> a >> b;
while (a > 0) {
a--;
t++;
if (t % b == 0) t++;
}
cout << t;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, sum = 0, hours = 0;
cin >> a >> b;
for (int i = 0; i < a; i++) {
hours += 1;
sum += 1;
if (sum == b) {
a += 1;
sum = 0;
}
}
cout << hours;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, v, l, y;
cin >> a >> b;
int ans = a;
v = a;
while (v >= b) {
y = v % b;
v = v / b;
ans += v;
v = v + y;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int a, b, t, c, j, k, T, i, A[1028], B[1028], C[1028];
int main() {
cin >> a >> b;
while (a > 0) {
a--;
t++;
if (t == b) {
t = 0;
a++;
}
j++;
}
cout << j;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, sum = 0;
cin >> a >> b;
int temp = 0;
while (a >= b) {
temp = a % b;
a -= temp;
sum += a;
a /= b;
a += temp;
}
sum += a;
cout << sum;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, i;
cin >> a >> b;
c = a;
while ((a / b) != 0) {
c += (a / b);
i = a % b;
a /= b;
a += i;
}
cout << c;
}
|
#include <bits/stdc++.h>
using namespace std;
int naiveSoln(int nCandles, int combineCandles) {
int result = 0;
int burning = nCandles, waste = 0;
while (burning) {
result += burning;
int totalWaste = burning + waste;
burning = totalWaste / combineCandles;
waste = totalWaste % combineCandles;
}
return result;
}
void test() {
int nCandles[] = {4, 6, 1000, 123};
int combineCandles[] = {2, 3, 1000, 5};
int rightAns[] = {7, 8, 1001, 153};
for (int i = 0; i < 4; i++) {
int ourAns = naiveSoln(nCandles[i], combineCandles[i]);
cout << ourAns << endl;
cout << (ourAns == rightAns[i]) << endl;
}
}
int main() {
int nCandles, combineCandles;
cin >> nCandles >> combineCandles;
cout << naiveSoln(nCandles, combineCandles) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int calc(int a, int b, int cnt) {
if (a < b) return cnt;
cnt += a / b;
a = a / b + a % b;
return calc(a, b, cnt);
}
int main() {
int a, b;
scanf("%d%d", &a, &b);
int cnt = a;
printf("%d", calc(a, b, cnt));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a, b;
cin >> a >> b;
int cnt = a;
while (a >= b) {
a = a - b + 1;
cnt++;
}
cout << cnt;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, l = 0, aiz = 0;
cin >> a >> b;
while (true) {
l += a;
if (a == 0) {
cout << l;
break;
}
aiz += a;
a = aiz / b;
aiz %= b;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int count = 0;
int z = 0;
while (a > 0) {
count++;
a--;
z++;
if (z == b) {
z = 0;
a++;
}
}
cout << count;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int arr[100010];
int main() {
int a, b, newa, newb;
cin >> a >> b;
bool flag = true;
int ans = a;
while (true) {
newa = a;
newa = a / b;
if (newa == 0) break;
newb = a % b;
ans += newa;
a = newa + newb;
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, q = 0, time = 0, k;
cin >> a >> b;
k = a;
while (k != 0) {
k--;
q++;
time++;
if (q == b) {
k++;
q = 0;
}
}
cout << time;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int a, b;
cin >> a >> b;
int n = a, r = 0, s = 0;
while (n || r >= b) {
s += n;
r += n;
n = 0;
n += r / b;
r = r % b;
}
cout << s;
}
int main() {
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a;
cin >> n >> m;
int num = n;
while (n >= m) {
a = n % m;
n = n / m;
num += n;
n += a;
}
cout << num;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a, b;
cin >> a >> b;
cout << a + (a - 1) / (b - 1) << endl;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int a, b, t = 0;
scanf("%d%d", &a, &b);
t = a;
while (a >= b) {
t += a / b;
a = a % b + a / b;
}
printf("%d", t);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int ans = 0, take = 0;
while (n) {
ans++;
n--;
take++;
if (take == k) {
take = 0;
n++;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int ans = 0;
int check = 0;
while (a > 0) {
++ans;
a--;
++check;
if (check == b) {
++a;
check = 0;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, t = 0, c = 0;
cin >> a >> b;
t += a;
while (b <= a) {
c = a % b;
a /= b;
t += a;
a += c;
}
cout << t << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, m;
void in() { cin >> n >> m; }
void out() {
long long sum{0}, r{0};
while (n > 0) {
while (n > 0) {
sum += n;
r += n % m;
n /= m;
}
n = r / m;
r = r % m;
}
cout << sum;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
while (t--) {
in();
out();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int ans = 0;
if (a >= b) {
ans = a + a / b;
a += -a + a / b + a % b;
while (a >= b) {
ans += a / b;
a += -a + a / b + a % b;
}
} else {
ans = a;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
int main() {
int a, b, i, rem, sum;
scanf("%d %d", &a, &b);
for (i = sum = a; a > 0; i = a + rem) {
a = i / b;
rem = i % b;
sum += a;
}
printf("%d", sum);
}
|
#include <bits/stdc++.h>
int main() {
int a, b, x, y, ans;
scanf("%d %d", &a, &b);
ans = a;
while (a >= b) {
x = a / b;
ans = ans + x;
y = a % b;
a = x + y;
}
printf("%d", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int ans = a;
while (a >= b) {
ans += (a / b);
a = (a / b) + (a % b);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, count = 0, a, b = 0;
cin >> n >> k;
while (n != 0) {
count = count + n;
b = b + n;
n = b / k;
b = b % k;
}
cout << count;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, ans = 0, d, e;
cin >> a >> b;
ans = a + (a / b);
d = b;
e = (a / b) + (a % b);
while (true) {
if ((e) >= d) {
ans += (e / d);
e = (e % d) + (e / d);
} else {
break;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int sum = a;
while (a >= b) {
int x = a / b;
sum = sum + x;
a = x + (a % b);
}
cout << sum << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void cmin(T& a, T b) {
if (b < a) a = b;
}
template <typename T>
void cmax(T& a, T b) {
if (a < b) a = b;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a, b;
while (cin >> a >> b) {
int ans = a;
int mod = 0;
while (a >= b) {
mod = a % b;
a /= b;
ans += a;
a += mod;
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int a;
int b;
scanf("%d", &a);
scanf("%d", &b);
int x = a;
int r;
do {
if ((a % b) == 0) {
a = a / b;
x = x + a;
} else {
r = a % b;
a = a - r;
a = a / b;
x = x + a;
a = a + r;
}
if (a < b) {
a = 0;
}
} while (a != 0);
printf("%d", x);
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,fast-math")
inline void setup() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
}
inline void solve();
int main(int argc, char* argv[]) {
setup();
long long t = 1;
while (t--) solve();
return 0;
}
using namespace std;
inline void solve() {
long long a, b;
cin >> a >> b;
long long newCandles = a;
long long burnedOut = 0;
long long ans = 0;
while (newCandles || burnedOut >= b) {
ans += newCandles;
burnedOut += newCandles;
newCandles = (burnedOut / b);
burnedOut -= (newCandles * b);
}
cout << ans + newCandles;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, ans = 0;
cin >> a >> b;
ans = (a * b - 1) / (b - 1);
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int s = a;
int q = 0;
for (int i = 0;; i++) {
s += (a + q) / b;
int w = q;
q = (a + q) % b;
a = (a + w) / b;
if (a + q < b) {
break;
}
}
cout << s;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
long long ans = 0, cnt = 0;
while (n) {
n--;
ans++;
cnt++;
if (cnt == k) {
cnt = 0;
n++;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int a, b;
cin >> a >> b;
long long int ans = a;
while (a / b >= 1) {
ans += a / b;
a = a / b + a % b;
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
int C = 0;
int R = 0;
cin >> n >> m;
while (true) {
if (n == 0) break;
n--;
R++;
C++;
if (C == m) {
C = 0;
n++;
}
}
cout << R << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, m;
cin >> n >> m;
long long ans = 0;
long long broken = 0;
while (n > 0) {
ans++;
n--;
broken++;
if (broken == m) {
n++;
broken = 0;
}
}
cout << ans << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
srand(static_cast<unsigned>(time(0)));
long long t;
t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int hours_light_up;
hours_light_up = a;
int a1 = a;
hours_light_up = hours_light_up + a1 / b;
while (a1 / b >= b) {
a1 = a1 / b;
a1 = a1 + a - a1 * b;
a = a1;
hours_light_up = hours_light_up + a1 / b;
}
if (a1 / b < b) {
a1 = a1 / b;
a1 = a1 + a - a1 * b;
hours_light_up = hours_light_up + a1 / b;
}
cout << hours_light_up;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, i, x, y, z, j, len, cnt(0), sum = 0, a, b, c, temp, d, res = 0, k;
int dp[1000];
int two[1000][1000];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
string str, st;
int check(int n) {}
int main() {
cin >> a >> b;
res += a;
while (a >= b) {
d = a / b;
res += d;
a = d + a % b;
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007, INF = 2000000001;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
dy[] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
const double EPS = 1e-9;
long long gcd(long long a, long long b) { return (b != 0) ? gcd(b, a % b) : a; }
long long modpow(long long a, long long x, long long m = mod) {
int p = 1;
while (x > 0) {
if (x & 1 == 1) {
p = p * a % m;
--x;
} else {
x >>= 1;
a = a * a % m;
}
}
return p;
}
void z(const string& s, vector<int>& v) {
int n = s.length();
for (int i = 1, l = 0, r = 0; i < n; ++i) {
if (i <= r) v[i] = min(v[i - l], r - i + 1);
while (i + v[i] < n && s[v[i]] == s[i + v[i]]) ++v[i];
if (i + v[i] - 1 > r) r = (l = i) + v[i] - 1;
}
}
void dfs(vector<string>& maze, int x, int y, int& count) {
if (count > 0) {
int n = maze.size(), m = maze[0].size();
for (int d = 0; d < 4 && count > 0; ++d) {
int tx = x + dx[d], ty = y + dy[d];
if (ty >= 0 && ty < n && tx >= 0 && tx < m && maze[ty][tx] == '.') {
maze[ty][tx] = '@';
--count;
dfs(maze, tx, ty, count);
}
}
}
}
class P {
public:
double n, d;
P(double dd) : n(dd), d(dd - floor(n)) {}
};
class CP {
public:
bool operator()(const P& a, const P& b) const { return a.d < b.d; }
};
void _a() {
int a, b;
cin >> a >> b;
int c = a, left = 0;
while (a >= b) {
c += a / b;
left = a % b;
a = left + a / b;
left = 0;
}
cout << c;
}
void _b() {}
void _c() {}
void _d() {}
void _e() {}
long long gcdex(long long a, long long b, long long& x, long long& y) {
if (a == 0) {
x = 0;
y = 1;
return b;
} else {
long long x1, y1;
long long g = gcdex(b % a, a, x1, y1);
x = y1 - b / a * x1;
y = x1;
return g;
}
}
int main() {
_a();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << (a * b - 1) / (b - 1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a, b, c, i(0), j, t;
cin >> n >> m;
a = n;
t = n;
for (b = m; b <= a; b += m) {
t++;
a++;
}
cout << t;
return 0;
}
|
#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;
scanf("%d%d", &a, &b);
int tmp;
int tmpm;
int ans = a;
while (1) {
tmp = a / b;
if (tmp == 0) break;
tmpm = a % b;
a = tmp + tmpm;
ans += tmp;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a, b, ans;
int main() {
cin >> a >> b;
while (a >= b) {
ans += (a / b) * b;
a = (a / b) + (a % b);
}
ans += a;
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int const GRAY = -2;
int const BLACK = -1;
int const WHITE = 0;
int const INF = 1e8;
long long const INF64 = 1e18;
template <typename T>
void alert(const T& t) {
cout << t;
exit(0);
}
int ugcd(int a, int b) { return b ? ugcd(b, a % b) : a; }
int gcd(int a, int b) { return ugcd(a, b) * ((a < 0) ^ (b < 0) ? -1 : +1); }
int lcm(int a, int b) { return abs(a * b) / gcd(a, b); }
int main(int argc, char* argv[]) {
int a, b;
cin >> a >> b;
int ans = a;
int c = a;
while (c >= b) {
ans += c / b;
c = c % b + c / b;
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
;
int k;
cin >> k;
;
int cnt = 0;
;
cnt += n;
while (n >= k) {
cnt += n / k;
n = n / k + n % k;
}
cout << cnt;
}
|
#include <bits/stdc++.h>
using namespace std;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, -1, 1};
const double eps = 1e-9;
const int INF = 0x7FFFFFFF;
const long long INFLL = 0x7FFFFFFFFFFFFFFFLL;
const double pi = acos(-1);
template <class T>
T take(queue<T> &O) {
T tmp = O.front();
O.pop();
return tmp;
}
template <class T>
T take(stack<T> &O) {
T tmp = O.top();
O.pop();
return tmp;
}
template <class T>
T take(priority_queue<T> &O) {
T tmp = O.top();
O.pop();
return tmp;
}
template <class T>
inline void getint(T &num) {
bool neg = 0;
num = 0;
char c;
while ((c = getchar_unlocked()) && (!isdigit(c) && c != '-'))
;
if (c == '-') {
neg = 1;
c = getchar_unlocked();
}
do num = num * 10 + c - '0';
while ((c = getchar_unlocked()) && isdigit(c));
num *= (neg) ? -1 : 1;
}
void OPEN(string in = "input.txt", string out = "output.txt") {
freopen(in.c_str(), "r", stdin);
freopen(out.c_str(), "w", stdout);
return;
}
int a, b, ans;
int main() {
getint(a);
getint(b);
ans += a;
int c = b;
while (a / b) {
ans += a / b;
a = a / b + a % b;
}
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, h = 0, t = 0;
cin >> a >> b;
h += a;
while (a >= b) {
h += a / b;
t = a % b;
a = a / b;
a += t;
}
cout << h;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int power(int x, int y) {
int res = 1;
x = x % mod;
while (y > 0) {
if (y & 1) res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res;
}
int ncr(int n, int r) {
int res = 1;
if (r > n - r) r = n - r;
for (int i = 0; i < r; i++) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
int gcd(int a, int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
int lcm(int a, int b) { return (a / gcd(a, b) * b); }
int max(int a, int b) {
int ans = a > b ? a : b;
return ans;
}
int min(int a, int b) {
int ans = a < b ? a : b;
return ans;
}
int main() {
long long n, b, t = 0;
cin >> n >> b;
while (n >= b) {
n = n - b + 1;
t += b;
}
cout << t + n;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << ((a * b) - 1) / (b - 1);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a, b;
cin >> a >> b;
int ans = a;
while (a >= b) {
int t = a / b;
ans += t;
a = t + (a - b * t);
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int a, b, c, d, i, j, k, l, count = 0;
scanf("%d %d", &a, &b);
if (a < b) {
printf("%d", a);
exit(0);
}
k = a;
while (k >= b) {
c = k / b;
d = k % b;
count += c;
k = c + d;
}
printf("%d", (count + a));
}
|
#include <bits/stdc++.h>
using namespace std;
int solve(int n, int k) {
int total_candles = n;
int candles = n;
while (candles >= k) {
total_candles += candles / k;
candles = candles / k + candles % k;
}
return total_candles;
}
int main() {
int a, b;
cin >> a >> b;
cout << solve(a, b);
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.