Pagini recente » Cod sursa (job #435516) | Istoria paginii runda/concurs_12 | Cod sursa (job #2711556) | Cod sursa (job #1403726) | Cod sursa (job #2552499)
#include <iostream>
#include <fstream>
using namespace std;
ifstream R("pascal.in");
ofstream w("pascal.out");
int v[5000001];
int main()
{
int r, d, put=0, cnt=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)
{
v[i]=v[i/3]+1;
}
}
for(int i=1; i<r/2; i++)
{
put=put+v[r-i+1]-v[i];
if(put>=2)
{
cnt++;
}
}
}
if(d==2||d==3||d==5)
{
if(r%2==0 && put!=0)
{
w<<cnt*2-1;
}
else
{
w<<cnt*2;
}
}
else
{
if(r%2==0 && put>=2)
{
w<<cnt*2-1;
}
else
{
w<<cnt*2;
}
}
return 0;
}