Pagini recente » Cod sursa (job #3197462) | Cod sursa (job #3162944) | Cod sursa (job #1665335) | Cod sursa (job #3179488) | Cod sursa (job #2764471)
#include <fstream>
#include <iostream>
using namespace std;
int R, D;
int rez;
void read() {
ifstream f("pascal.in");
f >> R >> D;
f.close();
}
void solve() {
// randurile 0 si 1 nu pot avea elemente divizibile cu 2, 3, 4, 5, 6 => afisam 0
if (R == 0 || R == 1)
return;
int i, p2, p3, aux, put, ok;
for (i = 1; i <= R; i++) {
p2 = 0, p3 = 0;
if (D % 2 == 0) {
aux = R, put = 2;
while (aux >= put) {
p2 += aux / put;
put *= 2;
}
aux = i - 1, put = 2;
while (aux >= put) {
p2 -= aux / put;
put *= 2;
}
aux = R - i + 1, put = 2;
while (aux >= put) {
p2 -= aux / put;
put *= 2;
}
}
if (D % 3 == 0) {
aux = R, put = 3;
while (aux >= put) {
p3 += aux / put;
put *= 3;
}
aux = i - 1, put = 3;
while (aux >= put) {
p3 -= aux / put;
put *= 3;
}
aux = R - i + 1, put = 3;
while (aux >= put) {
p3 -= aux / put;
put *= 3;
}
}
ok = 1;
if (D % 2 == 0 && p2 < 1)
ok = 0;
if (D % 4 == 0 && p2 < 2)
ok = 0;
if (D % 3 == 0 && p3 < 1)
ok = 0;
rez += ok;
}
}
void output() {
ofstream g("pascal.out");
g << rez;
g.close();
}
int main() {
read();
solve();
output();
return 0;
}