1. 程式人生 > 其它 >A. K-divisible Sum

A. K-divisible Sum

技術標籤:AC路漫漫

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two integersnandk.

You should create an array ofnpositive integersa1,a2,…,ansuch that the sum(a1+a2+⋯+an)is divisible bykand maximum element inais minimum possible.

What is the minimum possible maximum element ina?

Input

The first line contains a single integert(1≤t≤1000)— the number of test cases.

The first and only line of each test case contains two integersnandk(1≤n≤109;1≤k≤109).

Output

For each test case, print one integer— the minimum possible maximum element in array

asuch that the sum(a1+⋯+an)is divisible byk.

Example

input

Copy

4
1 5
4 3
8 8
8 17

output

Copy

5
2
1
3

Note

In the first test casen=1, so the array consists of one elementa1and if we makea1=5it will be divisible byk=5and the minimum possible.

In the second test case, we can create arraya=[1,2,1,2]. The sum is divisible by

k=3and the maximum is equal to2.

In the third test case, we can create arraya=[1,1,1,1,1,1,1,1]. The sum is divisible byk=8and the maximum is equal to1.

解題說明:此題是一道數學題,可以分情況討論,k大於n時判斷k是否能被n整除,如果能整除那就是k/n,否則最大值肯定就增加1。反過來,k小於n時判斷n是否能被k整除,能除那就是最小值1,否則為2.

#include<stdio.h>

int main() 
{
	int t, n, k;
	scanf("%d", &t);
	while (t != 0)
	{
		scanf("%d %d", &n, &k);
		if (k >= n) 
		{
			if (k%n != 0)
			{
				printf("%d\n", k / n + 1);
			}
			else
			{
				printf("%d\n", k / n);
			}
		}
		else 
		{
			if (n%k == 0)
			{
				printf("1\n");
			}
			else
			{
				printf("2\n");
			}
		}
		t--;
	}
	return 0;
}