Pagini recente » Cod sursa (job #233284) | Cod sursa (job #1986033) | Cod sursa (job #3274314) | Cod sursa (job #2236989) | Cod sursa (job #825464)
Cod sursa(job #825464)
#include <iostream>
#include <cstdlib>
#include <cstdio>
int A[7];
using namespace std;
int verif(int D)
{
if ( D == 4 && A[2] > 1)
{
return 1;
}
if (D == 6 && A[2]> 0 && A[3] > 0)
{
return 1;
}
if (A[D] > 0)
{
return 1;
}
return 0;
}
int get_divs(int a , int b)
{
while (a % 2 == 0)
{
a /= 2;
A[2] ++;
}
while (a % 3 == 0)
{
a /= 3;
A[3] ++;
}
while (a % 5 == 0)
{
a /= 5;
A[5]++;
}
while (b % 2 == 0)
{
b /= 2;
A[2] --;
}
while (b % 3 == 0)
{
b /= 3;
A[3] --;
}
while (b % 5 == 0)
{
b /= 5;
A[5]--;
}
}
int main()
{
FILE *input = fopen("pascal.in","r");
FILE *output = fopen("pascal.out","w");
int N, D;
fscanf(input,"%d%d",&N,&D);
int M = N;
int raspuns = 0;
for (int i = 1;i<=(M/2);i++,N--)
{
get_divs(N,i);
if (verif(D) == 1)
{
raspuns += 2;
}
}
if (M % 2 == 0 && verif(D))
{
raspuns --;
}
fprintf(output,"%d",raspuns);
fclose(input);
fclose(output);
return 0;
}