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之間的整數(shù)。 他必須重新參加每一次失敗的考試,即獲得 2 分的考試。
作者需要花費(fèi)太多的時間和精力才能使他的分?jǐn)?shù)總和嚴(yán)格超過 k。 這可能會破壞 Codeforces 回合。 另一方面,如果他的分?jǐn)?shù)總和嚴(yán)格小于 k,作者的媽媽根本不會高興。
Codeforces 的作者非常聰明,他們總是能得到自己選擇的分?jǐn)?shù)。 此外,Codeforces 作者只是討厭重新參加考試。
幫助作者求出如果他通過了考試,那么他需要重考的最少考試次數(shù),使得所有 n 次考試的分?jǐn)?shù)總和恰好等于 k。
輸入
單個輸入行包含空格分隔的整數(shù) n 和 k (1?≤?n?≤?50, 1?≤?k?≤?250) — 考試數(shù)量和所需的分?jǐn)?shù)總和。
保證存在一種通過n次考試的方法,使得分?jǐn)?shù)之和恰好等于k。
輸出
打印單個數(shù)字 — 考慮到所有考試的分?jǐn)?shù)總和必須等于 k,作者將獲得 2 分的最少考試次數(shù)。
--------------------------
求2個數(shù)的商,如果商為2 ,那么再看余數(shù),考試為2分的場數(shù)應(yīng)該是總場數(shù)-余數(shù)。
如果商大于2,那么一定是0;
下面是代碼: