C. Table Tennis Game 2

Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.

Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.

Note that the game consisted of several complete sets.

Input

The first line contains three space-separated integers ka and b (1 ≤ k ≤ 1090 ≤ a, b ≤ 109a + b > 0).

Output

If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.

Examples
input
11 11 5
output
1
input
11 2 3
output
-1
Note

Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.



思路:
先说题意,A,B两人打乒乓球赛,回合制,一回合中,赢一球得一分,对方不得分。其中之一得到的分数等于
k值,当前回合结束,分数清零。现在给你两个人比赛里的总分a和b,求最多打几回合。
理解:
使回合最多,那肯定是k:0或者是0:k的评分时,也就是最多有a/k+b/k回合。
注意,不可能情况就输出-1,什么事不可能情况。
若,a%k!=0,那么在B会胜利的一局中将那个余数消耗掉。所以当a%k&&b/k==0时,输出-1;
同理,b%k&&a/k==0也是。

代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    int m=a/n+b/n;
    if(a/n==0&&b%n||b/n==0&&a%n)
        cout<<"-1"<<endl;
    else
        cout<<m<<endl;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值