Pagini recente » Cod sursa (job #1450137) | Cod sursa (job #1904298) | Cod sursa (job #989408) | Cod sursa (job #2637907) | Cod sursa (job #2650347)
#include<bits/stdc++.h>
#define fore(start,i,end) for(int i = start; i <= end; i++)
#define dbg(x) #x << "=" << x << " "
#define dbg2(x,y) "{" << x << "," << y << "} "
#define dbg3(x,y,k) "{" << x << "," << y << "," << k << "} "
#define dbg4(x,y,k,j) "{" << x << "," << y << "," << k << " , " << j << "} "
#define ll long long
#define f1 first
#define f2 second
#define inf 1000000005
#define debug_st(st) if (true) {cout << #st << " : "; stack<int> s123; while (!s123.empty()) cout << s123.top() << " ", s123.pop(); cout << "\n";}
#define debug_a(a,n) cout << #a << " : "; for(int i = 1; i <= n; i++) cout << a[i] << " "; cout << "\n";
#define debug_m(a,n,m) cout << #a << " :\n"; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++) cout << a[i][j] << " "; cout << "\n"; }cout << "\n";
#define debug_v(v) cout << #v << " : "; for(auto k : v) cout << k << " "; cout << "\n";
#define debug_s(s) cout << #s << " : "; for (auto k : s) cout << k < " "; cout << "\n";
#define debug_s2(s) cout << #s << " : "; for(auto k : s) cout << dbg2((*k).first,(*k).second); cout << "\n";
#define nmax 5000005
using namespace std;
ifstream in("pascal.in");
ofstream out("pascal.out");
int y,d,f2[nmax],f3[nmax],f5[nmax];
int main()
{int i,j,ans = 0;
in >> y >> d;
for (i = 1; i <= y; i++)
{
int x = i;
int nr2 = 0, nr3 = 0 , nr5 = 0;
if (d == 2 || d == 4 || d == 6)
while (x % 2 == 0)
{
nr2++;
x = (x >> 1);
}
x = i;
if (d == 3 || d== 6)
while (x % 3 == 0)
{
nr3++;
x /= 3;
}
x = i;
if (d == 5)
while (x % 5 == 0)
{
nr5++;
x /= 5;
}
f2[i] = nr2 + f2[i - 1];
f3[i] = nr3 + f3[i - 1];
f5[i] = nr5 + f5[i - 1];
}
// for (i = 1; i <= y; i++)
// {
// cout << dbg(i) << dbg(f2[i]) << dbg(f3[i]) << dbg(f5[i]) << "\n";
// }
if (d== 2){
for (j = 0; j <= y; j++)
{
int nr2 = f2[y] - f2[y - j] - f2[j];
//int nr3 = f3[y] - f3[y - j] - f3[j];
//int nr5 = f5[y] - f5[y - j] - f5[j];
if (nr2 > 0) ans++;
}
}
if (d== 3){
for (j = 0; j <= y; j++)
{
// int nr2 = f2[y] - f2[y - j] - f2[j];
int nr3 = f3[y] - f3[y - j] - f3[j];
// int nr5 = f5[y] - f5[y - j] - f5[j];
if (nr3 > 0) ans++;
}
}
if (d== 4){
for (j = 0; j <= y; j++)
{
int nr2 = f2[y] - f2[y - j] - f2[j];
//int nr3 = f3[y] - f3[y - j] - f3[j];
// int nr5 = f5[y] - f5[y - j] - f5[j];
if (nr2 >= 2) ans++;
}
}
if (d== 5){
for (j = 0; j <= y; j++)
{
// int nr2 = f2[y] - f2[y - j] - f2[j];
// int nr3 = f3[y] - f3[y - j] - f3[j];
int nr5 = f5[y] - f5[y - j] - f5[j];
if (nr5 >= 1) ans++;
}
}
if (d== 6){
for (j = 0; j <= y; j++)
{
int nr2 = f2[y] - f2[y - j] - f2[j];
int nr3 = f3[y] - f3[y - j] - f3[j];
// int nr5 = f5[y] - f5[y - j] - f5[j];
if (nr2 > 0 && nr3 > 0)
ans++;
}
}
out << ans << "\n";
}