Pagini recente » Cod sursa (job #553575) | Cod sursa (job #2503882) | Cod sursa (job #749278) | Cod sursa (job #1984520) | Cod sursa (job #2648162)
#include <bits/stdc++.h>
using namespace std;
ifstream R("pascal.in");
ofstream w("pascal.out");
int v[5000001], g[5000001];
int main()
{
int r, d, put=0, cnt=0, put2=0;
R>>r>>d;
if(d==2)
{
for(int i=2; i<=r; i++)
{
if(i%2==0)
{
v[i]=v[i/2]+1;
}
}
for(int i=1; i<=r/2; i++)
{
put=put+v[r-i+1]-v[i];
if(put!=0)
{
cnt++;
}
}
}
else if(d==3)
{
for(int i=3; i<=r; i++)
{
if(i%3==0)
{
v[i]=v[i/3]+1;
}
}
for(int i=1; i<=r/2; i++)
{
put=put+v[r-i+1]-v[i];
if(put!=0)
{
cnt++;
}
}
}
else if(d==4)
{
for(int i=2; i<=r; i++)
{
if(i%2==0)
{
v[i]=v[i/2]+1;
}
}
for(int i=1; i<=r/2; i++)
{
put=put+v[r-i+1]-v[i];
if(put>=2)
{
cnt++;
}
}
}
else if(d==5)
{
for(int i=5; i<=r; i++)
{
if(i%5==0)
{
v[i]=v[i/5]+1;
}
}
for(int i=1; i<=r/2; i++)
{
put=put+v[r-i+1]-v[i];
if(put!=0)
{
cnt++;
}
}
}
else if(d==6)
{
for(int i=2; i<=r; i++)
{
if(i%2==0)
{
v[i]=v[i/2]+1;
}
if(i%3==0)
{
g[i]=g[i/3]+1;
}
}
for(int i=1; i<=r/2; i++)
{
put=put+v[r-i+1]-v[i];
put2=put2+g[r-i+1]-g[i];
if(put>=1&&put2>=1)
{
cnt++;
}
}
}
if(d==2||d==3||d==5)
{
if(r%2==0 && put!=0)
{
w<<cnt*2-1;
}
else
{
w<<cnt*2;
}
}
else if(d==4)
{
if(r%2==0 && put>=2)
{
w<<cnt*2-1;
}
else
{
w<<cnt*2;
}
}
else if(d==6){
if(r%2==0 && put>=1 && put2>=1){
w<<cnt*2-1;
}
else{
w<<cnt*2;
}
}
return 0;
}