0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

P7893 『JROI-3』黑白棋

R59042842
This commit is contained in:
Baoshuo Ren 2021-10-03 19:21:46 +08:00 committed by Baoshuo Ren
parent d5696176ac
commit 9317dd1aeb
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
int t;
long long n, p, f, ans;
int main() {
scanf("%d", &t);
while (t--) {
ans = 0;
f = 1;
scanf("%lld%lld", &n, &p);
if (p == 1) {
printf("0\n");
continue;
}
for (long long k = n; k; k /= p) {
ans += f * k;
f = -f;
}
printf("%lld\n", ans);
}
return 0;
}