Cod sursa(job #661731)

Utilizator ciuscatalincius catalin ciuscatalin Data 15 ianuarie 2012 00:05:48
Problema Pascal Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#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;
}