Pagini recente » Cod sursa (job #600150) | Cod sursa (job #46149) | Cod sursa (job #2771249) | Cod sursa (job #2481850) | Cod sursa (job #673671)
Cod sursa(job #673671)
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
ifstream f("pascal.in");
ofstream g("pascal.out");
int r,d,aux=1;
int fact_r = 1;
int fact_rj = 1;
int fact_j = 1;
f>>r; // randul
f>>d; // nr cu care sa fie divizibil
int contor = 0;
if ((!r) || (!d)) g<<"1\n"; //
else { // citire valida
for (int j=0;j<=r;j++) {
//fact r
for (int k =1;k<=r;k++)
fact_r=fact_r*k;
//fact r-j
for (int k =1;k<=(r-j);k++)
fact_rj=fact_rj*k;
//fact j
for (int k =1;k<=j;k++)
fact_j=fact_j*k;
aux= fact_r / (fact_rj*fact_j);
fact_r = 1;
fact_rj = 1;
fact_j = 1;
if ( aux % d == 0)
contor++;
}
}
g<<contor;
f.close();
g.close();
return 0;
}