#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define pf printf
#define sf scanf
int main()
{
int n, m, temp=0, move;
while(sf("%d%d", &n, &m)==2)
{
if(n<m)
pf("-1\n");
if(n==m)
pf("%d\n", n);
else
{
if(n%2==0)
{
temp = n/2;
}
else
{
temp = (n-1)/2;
temp += 1;
}
move = 0;
while(temp!=n)
{
if(temp%m==0)
{
move = temp;
pf("%d\n", move);
break;
}
else
{
temp++;
}
}
}
}
return 0;
}
#include<cstdio>
#include<cmath>
using namespace std;
#define pf printf
#define sf scanf
int main()
{
int n, m, temp=0, move;
while(sf("%d%d", &n, &m)==2)
{
if(n<m)
pf("-1\n");
if(n==m)
pf("%d\n", n);
else
{
if(n%2==0)
{
temp = n/2;
}
else
{
temp = (n-1)/2;
temp += 1;
}
move = 0;
while(temp!=n)
{
if(temp%m==0)
{
move = temp;
pf("%d\n", move);
break;
}
else
{
temp++;
}
}
}
}
return 0;
}
No comments:
Post a Comment