mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-10 02:18:48 +00:00
P7893 『JROI-3』黑白棋
R59042842
This commit is contained in:
parent
d5696176ac
commit
9317dd1aeb
25
Luogu/problem/P7893/P7893.cpp
Normal file
25
Luogu/problem/P7893/P7893.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user