Cod sursa(job #2375394)

Utilizator iandavidroIan David Bocioaca iandavidro Data 8 martie 2019 08:52:39
Problema Pascal Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <bits/stdc++.h>
using namespace std;

ifstream f("pascal.in");
ofstream g("pascal.out");

int n,d,i,up;
int down,sol;
int cnt[10];
inline void upd(int,int,int);
inline void upd(int,int,int);
void solve2();
void solve3();
void solve4();
void solve5();
void solve6();

int main(){
    f>>n>>d;
    if(d==2)solve2();
    if(d==3)solve3();
    if(d==4)solve4();
    if(d==5)solve5();
    if(d==6)solve6();
    g<<sol;
    return 0;
}
inline void upd(int u,int d,int v)
{
    while(u%v==0){
        u/=v;
        cnt[v]++;
    }
    while(d%v==0){
        d/=v;
        cnt[v]--;
    }
}
void solve2()
{
    for(up=n,down=1;down<=n;up--,down++)
    {
        upd(up,down,2);
        if(cnt[2]){
            sol++;
        }
    }
}
void solve3()
{
    for(up=n,down=1;down<=n;up--,down++)
    {
        upd(up,down,3);
        if(cnt[3]){
            sol++;
        }
    }
}
void solve4()
{
    for(up=n,down=1;down<=n;up--,down++)
    {
        upd(up,down,2);
        if(cnt[2]>1){
            sol++;
        }
    }
}
void solve5(){
    for(up=n,down=1;down<=n;up--,down){
        upd(up,down,5);
        if(cnt[5]){
            sol++;
        }
    }
}
void solve6(){
    for(up=n,down=1;down<=n;up--,down++){
        upd(up,down,2);
        upd(up,down,3);
        if(cnt[2]&&cnt[3]){
            sol++;
        }
    }
}