Pagini recente » Cod sursa (job #2212055) | Cod sursa (job #95374) | Cod sursa (job #2468002) | Cod sursa (job #254705) | Cod sursa (job #2488636)
#include <fstream>
using namespace std;
ifstream in("pascal.in");
ofstream out("pascal.out");
int r, d, nr = 0;
int exp(int n, int p) {
int g = p, s = 0;
while (n >= g) {
s += n / g;
g *= p;
}
return s;
}
int main() {
ios_base::sync_with_stdio(false);
in.tie(NULL), out.tie(NULL);
in >> r >> d;
if (d == 2 || d == 3 || d == 5) {
int g = exp(r, d);
for (int i = 0; i <= r / 2; i++)if ((g - exp(i, d) - exp(r - i, d)) >= 1)nr++;
if (r % 2 == 0) {
out << nr * 2 - 1;
}
else {
out << nr * 2;
}
}
if(d == 4) {
int g = exp(r, 2);
for (int i = 0; i <= r / 2; i++)if ((g - exp(i, 2) - exp(r - i, 2)) >= 2)nr++;
if (r % 2 == 0) {
out << nr * 2 - 1;
}
else {
out << nr * 2;
}
}
if (d == 6) {
int g = exp(r, 2), h = exp(r, 3);
for (int i = 0; i <= r / 2; i++)if ((g - exp(i, 2) - exp(r - i, 2)) >= 1 && (h - exp(i, 3) - exp(r - i, 3)) >= 1)nr++;
if (r % 2 == 0) {
out << nr * 2 - 1;
}
else {
out << nr * 2;
}
}
return 0;
}