题目:
题意分析:
水题一枚,给出一个N。然后分解N,只能分解为1和2。考虑全部分解为1的情况,则最多需要N步,全部分解为2的情况,如果为奇数N/2+1 偶数N/2.然后枚举,验证就行了。
代码:
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
int main()
{
int n,m,i;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n%2==0)
{
for(i=n/2;i<=n;i++)
{
if(i%m==0)
{
printf("%d\n",i);
break;
}
}
if(i==n+1)
printf("-1\n");
}
if(n%2==1)
{
for(i=n/2+1;i<=n;i++)
{
if(i%m==0)
{
printf("%d\n",i);
break;
}
}
if(i==n+1)
printf("-1\n");
}
}
return 0;
}