Pagini recente » Cod sursa (job #1781650) | Cod sursa (job #2541440) | Cod sursa (job #1464743) | Cod sursa (job #2025743) | Cod sursa (job #1596075)
#include <fstream>
using namespace std;
ifstream cin("pascal.in");
ofstream cout("pascal.out");
int fact[10], ans;
void factor(int x, int f, int sign)
{
int p = 0;
while(x%f==0)
{
p++;
x = x/f;
}
fact[f] += p*sign;
}
int main()
{
int n, d;
cin>>n>>d;
for(int k=1; k<=(n-1)/2; k++){
if(d%2==0){
factor(n-k+1, 2, 1);
factor(k, 2, -1);
}
if(d%3==0){
factor(n-k+1, 3, 1);
factor(k, 3, -1);
}
if(d%5==0){
factor(n-k+1, 5, 1);
factor(k, 5, -1);
}
if(d==2 and fact[2]>0) ans+=2;
if(d==3 and fact[3]>0) ans+=2;
if(d==4 and fact[2]>1) ans+=2;
if(d==5 and fact[5]>0) ans+=2;
if(d==6 and fact[2]>0 and fact[3]>0) ans += 2;
}
if(n%2==0){
factor(n-n/2+1, 2, 1);
factor(n-n/2+1, 3, 1);
factor(n-n/2+1, 5, 1);
factor(n/2, 2, -1);
factor(n/2, 3, -1);
factor(n/2, 5, -1);
if(d==2 and fact[2]>0) ans+=1;
if(d==3 and fact[3]>0) ans+=1;
if(d==4 and fact[2]>1) ans+=1;
if(d==5 and fact[5]>0) ans+=1;
if(d==6 and fact[2]>0 and fact[3]>0) ans += 1;
}
cout<<ans;
return 0;
}