Cod sursa(job #673669)

Utilizator ciuscatalincius catalin ciuscatalin Data 4 februarie 2012 19:32:46
Problema Pascal Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>
using namespace std;
int divizibil( int x, int y ) 
{
    if (x % y == 0)
    return 1;
    else
    return 0;
}

int fact (int x)
{
    int temp=1;
    for (int i=1;i<=x;i++)
    temp = temp * i;
    return temp;
}

int main(int argc, char *argv[])
{
    ifstream f("pascal.in");
	ofstream g("pascal.out");
	int r,d,aux;
	f>>r;
	f>>d; 
	int contor = 0;
    if ((!r) || (!d)) g<<"1\n"; //
    else 
    {
         for (int j=0;j<=r;j++)
         {
             aux= fact(r) / (fact(r-j)*fact(j));
             if (divizibil(aux,d)==1)
             contor++;
         }
   	}
	g<<contor;
	f.close(); 
    g.close();
    return 0;
}