CF 194A - Exams
One day the Codeforces round author sat exams. He had n exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than k. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than k, the author's mum won't be pleased at all.
The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams.
Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all n exams equal exactly k.
Input
The single input line contains space-separated integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass n exams in the way that makes the sum of marks equal exactly k.
Output
Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal k.
-----------------------------
有一天,Codeforces 回合的作者参加了考试。 他有n次考试,每次考试他都需要得到一个2到5之间的整数。 他必须重新参加每一次失败的考试,即获得 2 分的考试。
作者需要花费太多的时间和精力才能使他的分数总和严格超过 k。 这可能会破坏 Codeforces 回合。 另一方面,如果他的分数总和严格小于 k,作者的妈妈根本不会高兴。
Codeforces 的作者非常聪明,他们总是能得到自己选择的分数。 此外,Codeforces 作者只是讨厌重新参加考试。
帮助作者求出如果他通过了考试,那么他需要重考的最少考试次数,使得所有 n 次考试的分数总和恰好等于 k。
输入
单个输入行包含空格分隔的整数 n 和 k (1 ≤ n ≤ 50, 1 ≤ k ≤ 250) — 考试数量和所需的分数总和。
保证存在一种通过n次考试的方法,使得分数之和恰好等于k。
输出
打印单个数字 — 考虑到所有考试的分数总和必须等于 k,作者将获得 2 分的最少考试次数。
--------------------------
求2个数的商,如果商为2 ,那么再看余数,考试为2分的场数应该是总场数-余数。
如果商大于2,那么一定是0;
下面是代码: