Cod sursa(job #613289)

Utilizator AllenSmailovic Alen Allen Data 20 septembrie 2011 19:56:19
Problema Pascal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <iostream>
#include <fstream>

using namespace std;

int r,d,S;
int a[5000][5000];

void matrice()
{
    for (int i=0;i<=r;i++)
    {
        a[0][i]=1;
        a[i][i]=1;
    }
    for (int i=2;i<=r+1;i++)
        for (int j=1;j<i;j++)
            a[i][j]=a[i-1][j-1]+a[i-1][j];
}

void div()
{
    for (int i=0;i<(r/2)+1;i++)
        if (a[r+1][i]%d==0)
            S=S+1;
}

int main()
{
    ifstream fin("pascal.in");
    ofstream fout("pascal.out");

    fin>>r>>d;
    matrice();
    div();
    if (r>4)
        fout<<S*2;
    if (r<=4 && r!=3)
        fout<<S+1;
    if (r==3)
        fout<<S*2;
    fin.close();
    fout.close();
    return 0;
}