zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 103 (Rated for Div. 2) A. K-divisible Sum

    Educational Codeforces Round 103 (Rated for Div. 2) A. K-divisible Sum)

    题面

    You are given two integers (n) and (k).

    You should create an array of (n) positive integers (a1,a2,…,an) such that the sum ((a1+a2+⋯+an)) is divisible by (k) and maximum element in aa is minimum possible.

    What is the minimum possible maximum element in (a)?

    Input

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

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

    Output

    For each test case, print one integer — the minimum possible maximum element in array aa such that the sum ((a1+⋯+an)) is divisible by (k).

    Example

    input

    4
    1 5
    4 3
    8 8
    8 17

    output

    5
    2
    1
    3

    Note

    In the first test case (n=1), so the array consists of one element (a1) and if we make (a1=5) it will be divisible by (k=5) and the minimum possible.

    In the second test case, we can create array (a=[1,2,1,2]). The sum is divisible by (k=3) and the maximum is equal to (2).

    In the third test case, we can create array (a=[1,1,1,1,1,1,1,1]). The sum is divisible by (k=8) and the maximum is equal to (1).

    题目分析

    为了使构成的数组的最大值最小,只需要让数组中的元素尽可能相同即让数字都等于n / k,当n / k无法整除时,那么最大值就是 n / k向上取整(ceil)。但是,当(n>k)时便无法满足,这个时候我们需要让k倍增,使k刚好大于等于n,我们只需要k = k * ceil(k / n)就可以实现。最终输出答案即可。

    AC代码

    #include<bits/stdc++.h>
    using namespace std;
    #define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
    int t;
    long long n, k;
    
    int main(){
        io;
        cin >> t;
        while(t--){
    	    cin >> n >> k;
    		int t = k;
    		if(n > k){
    			k = k * (ceil((double)n / (double)k));
    		}
    		long long ans = ceil((double) k / (double)n);
    		cout << ans << endl;
        }
    
        return 0;
    }
    
  • 相关阅读:
    搭建 springboot selenium 网页文件转图片环境
    洛谷P1352没有上司的舞会-题解
    错误集合
    洛谷P1434滑雪-题解
    洛谷P1278单词游戏-题解
    洛谷P1219八皇后-题解
    洛谷P1443马的遍历-题解
    洛谷P1135奇怪的电梯-题解
    经验集合
    洛谷P1019单词接龙-题解
  • 原文地址:https://www.cnblogs.com/FrankOu/p/14347983.html
Copyright © 2011-2022 走看看