Minimum Number of Pizzas
Chef is throwing a party for his
friends. There is a pizza store nearby and he wants to buy pizza for his friends. Each pizza has exactly slices. Chef's friends get sad if one gets more slices than the other. Also, Chef gets sad if there are some pizza slices left. More formally, suppose Chef buys pizzas, then everyone is happy if and only if there is a way to distribute slices between friends.
You need to find the minimum number of pizzas Chef has to buy to share all the slices among his friends so that none of his friends gets sad. Note that Chef hates pizza and doesn't take any slices.
Input Format
- First line of input contains , the number of test cases. Then the test cases follow.
- Each test case contains two space-separated integers and , where is the number of friends of chef and is the number of slices in a pizza.
Output Format
For each test case, print the minimum number of pizzas chef has to buy to share among his friends so that none of his friends gets sad.
Constraints
Subtasks
- Subtask 1 (100 points): Original constraints
Sample Input 1
3
2 2
2 3
4 2
Sample Output 1
1
2
2
Explanation
- Test case : One pizza has slices. And there are friends. So chef can just buy one pizza and give one slice to one friend and another slice to another friend.
- Test case : One pizza has slices. And there are friends. So chef can't share one pizza without being left out with a slice. So he needs to buy at least pizzas. And if he buys pizzas, he can give slices to one friend and to another. So the minimum number of pizzas chef needs to buy is equal to .
- Test case : One pizza has slices. And there are friends. So chef can't share one pizza among the friends. So he needs to buy at least pizzas. And if he buys pizzas, he can give slice to each of his friends. So the minimum number of pizzas chef needs to buy is equal to .
Code:
#include <iostream>
using namespace std;
long long gcd(long long int a, long long int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
long long lcm(int a, int b)
{
return (a / gcd(a,b))*b;
}
signed main(){
long long int t;
cin>>t;
while(t--)
{
long long int n,k;
cin>>n>>k;
long long int res=lcm(n,k)/k;
cout<<res<<"\n";
}
return 0;
}
Comments
Post a Comment