Pagini recente » Cod sursa (job #1110660) | Cod sursa (job #1606898) | Cod sursa (job #2648441) | Cod sursa (job #2448808) | Cod sursa (job #661731)
Cod sursa(job #661731)
#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;
cout << aux << "\n";
//i!/((i-j)!*j!)
if ( aux % d == 0)
contor++;
}
}
g<<contor;
f.close();
g.close();
system("pause");
return EXIT_SUCCESS;
}