Cod sursa(job #1244945)

Utilizator AcuasPopescu Nicolae-Aurelian Acuas Data 18 octombrie 2014 14:08:46
Problema Pascal Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.27 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("pascal.in");
ofstream g("pascal.out");
int r,d,j,s,tj=1,tj1,c,d2,d3,d5;
int main()
{
    f>>r>>d;
    for(j=1;j<=r-1;j++){
        int m2=0 , m3=0 , m5=0 ;
        int temp=r-j+1;
        while(temp%2==0||temp%3==0||temp%5==0)
        {
            if(temp%2==0){
                m2++;
                temp/=2;
            }
            if(temp%3==0){
                m3++;
                temp/=3;
            }
            if(temp%5==0){
                m5++;
                temp/=5;
            }
        }
        temp=j;
        while(temp%2==0||temp%3==0||temp%5==0){
            if(temp%2==0){
                m2--;
                temp/=2;
            }
            if(temp%3==0){
                m3--;
                temp/=3;
            }
            if(temp%5==0){
                m5--;
                temp/=5;
            }
        }
        d2+=m2;
        d3+=m3;
        d5+=m5;
        switch(d){
            case 2: if(d2>0) c++; break;
            case 3: if(d3>0) c++; break;
            case 4: if(d2>=2) c++; break;
            case 5: if(d5>0) c++; break;
            case 6: if(d2>0&&d3>0) c++; break;
        }
    }
    g<<c<<endl;
    return 0;
}