Cod sursa(job #2375399)

Utilizator iandavidroIan David Bocioaca iandavidro Data 8 martie 2019 08:53:40
Problema Pascal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <bits/stdc++.h>

using namespace std;

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

int n,d,i,up,down,sol,cnt[10];

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++;
    }
}