Pagini recente » Cod sursa (job #2796850) | Cod sursa (job #1464495) | Cod sursa (job #214990) | Cod sursa (job #1608594) | Cod sursa (job #859192)
Cod sursa(job #859192)
#include <fstream>
using namespace std;
ifstream cin("pascal.in");
ofstream cout("pascal.out");
const int rmax = 5000002;
int R, D;
int curr[3], cond[3];
const int divs[3] = {2,3,5};
int main()
{
cin>>R>>D;
for(int k = 0;k < 3;k++) {
while(D%divs[k] == 0) {
cond[k]++;
D /= divs[k];
}
}
int ans = 0;
int r = (R - 1)/2;
for(int i = 1;i <= r;i++) {
bool isDivisible = true;
int aux[2] = {R - i + 1,i};
for(int k = 0;k < 3;k++) {
while(aux[0]%divs[k] == 0) {
curr[k]++;
aux[0] /= divs[k];
}
while(aux[1]%divs[k] == 0) {
curr[k]--;
aux[1] /= divs[k];
}
isDivisible &= (curr[k] >= cond[k]);
}
ans += isDivisible + isDivisible;
}
if(R%2 == 0) {
r++;
bool isDivisible = true;
int aux[2] = {R - r + 1,r};
for(int k = 0;k < 3;k++) {
while(aux[0]%divs[k] == 0) {
curr[k]++;
aux[0] /= divs[k];
}
while(aux[1]%divs[k] == 0) {
curr[k]--;
aux[1] /= divs[k];
}
isDivisible &= (curr[k] >= cond[k]);
}
ans += isDivisible;
}
cout<<ans;
return 0;
}