F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

A Hard Allocation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2429    Accepted Submission(s): 1148


Problem Description
One day, WNJXYK came out an excellent idea that he could give his friends his special cakes which made of kiwis to eat in parties. But the process of making this kind of special cakes is very complex. One day, his friend Kayaking gave him a formulation which allows WNJXYK to produce one special cake with exact one kiwi in no time. Now let us have a big party over anyone’s imagination.
To simply this question we can assume that WNJXYK invited m friends to his house and he only had n kiwis this time. He wanted to produce special cakes with Kayaking’s formulation and give them to his friends.
Usually, it maybe not possible for people to get exactly same number of cakes in some situations. We can assume that people who received the most one get x cakes and people who received the least get y cakes. WNJXYK wondered that what is the minimal value of |x-y|?
 

Input
The input starts with one line contains exactly one positive integer T which is the number of test cases.
Each test case contains one line with exactly two positive integer n,m which has been explained above.
 

Output
For each test case, output one line containing “y” where y is the number of minimal difference.
 

Sample Input
3 5 5 3 10 6 7
 

Sample Output
0 1 1
 

Hint

1<=T<=100,1<=n,m<=1000
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 14:48:02, Gzip enabled