Pagini recente » Cod sursa (job #3121166) | Cod sursa (job #1470251) | Cod sursa (job #6528) | Cod sursa (job #2184274) | Cod sursa (job #3251026)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream f("pascal.in");
ofstream g("pascal.out");
int r,d,nr,c;
const int NMAX=5000005;
int div2,div3,div5;
struct
{
int two,three,five;
}a[NMAX+5];
int calc_exp(int i, int p)
{
int cnt=0;
while ( i%p==0 )
{
cnt++;
i/=p;
}
return cnt;
}
int main()
{
ios_base::sync_with_stdio(false);
f.tie(NULL);
f >> r >> d;
if ( d==2 )
div2=1;
if ( d==3 )
div3=1;
if ( d==4 )
div2=2;
if ( d==5 )
div5=1;
for (int i=1; i<=r; i++ )
{
a[i].two=calc_exp(i,2);
a[i].three=calc_exp(i,3);
a[i].five=calc_exp(i,5);
}
for (int i=1; i<=r; i++ )
{
a[i].two+=a[i-1].two;
a[i].three+=a[i-1].three;
a[i].five+=a[i-1].five;
}
for (int i=1; i<r; i++ )
{
int exp2=a[r].two-a[i].two-a[r-i].two; // r!/(r-i)!*i!
int exp3=a[r].three-a[i].three-a[r-i].three;
int exp5=a[r].five-a[i].five-a[r-i].five;
if ( exp2>=div2 && exp3>=div3 && exp5>=div5 )
nr++;
}
g << nr;
return 0;
}