Educational Codeforces Round 103 (Rated for Div. 2)A. K-divisible Sum
地址:http://codeforces.com/contest/1476/problem/A
题意:
构造一个中的最大值尽可能小。
解析:
分情况。
n==k的时候,很明显,n个位置全放1为最佳。
n>k,首先n个位置全放1
n%k==0,那么已满足条件
n%k!=0,那么n%k这个数字,一定是小于n的,那么再在上面若干个地方放2,一定可以达到sum%k==0的目的,所以此时最大为2
n<k
n%k==0,直接全放k/n,否则向上取整。
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<map> using namespace std; const int maxn = 3e5+50; const int inf=99999999; typedef long long ll; int main() { int t; cin>>t; while(t--) { int n ,k ; cin>>n>>k; if(n==k) cout<<"1"<<endl; else if(n>k) { if(n%k!=0) cout<<"2"<<endl; else cout<<"1"<<endl; } else { if(k%n==0) cout<<k/n<<endl; else cout<<k/n+1<<endl; } } } //9 //1 4 1 1 4 1 4 1 4