Cod sursa(job #1168076)

Utilizator tudormaximTudor Maxim tudormaxim Data 6 aprilie 2014 21:11:13
Problema Pascal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include<fstream>
using namespace std;
ifstream in("pascal.in");
ofstream out("pascal.out");
int R,D,m,v[10],sol;

void descomp(int x, int y)
{
    while(x%2==0)
        x/=2,v[2]++;
    while(x%3==0)
        x/=3,v[3]++;
    while(x%5==0)
        x/=5,v[5]++;
    while(y%2==0)
        y/=2,v[2]--;
    while(y%3==0)
        y/=3,v[3]--;
    while(y%5==0)
        y/=5,v[5]--;
}
int Div()
{
    if(D==4 && v[2]>1)return 1;
    if(D==6 && v[2]>0 && v[3]>0)return 1;
    if(v[D]>0)return 1;
    return 0;
}
int main()
{
    in>>R>>D;
    m=R;
    for(int i=1;i<=m/2;i++,R--)
    {
        descomp(R,i);
        if(Div())
            sol+=2;
    }
    if(m%2==0&&Div())sol--;
    out<<sol<<"\n";
    in.close();out.close();
    return 0;
}