标签:style http io color ar os sp on 代码
UVA10673 - Play with Floor and Ceil(数论)
题目大意:给你x,k,要求你找出p,q:满足x = p?下取整(x/k) + q?上取整(x/k);
解题思路:分三种情况:1、x整除k,那么可以另p = 0,那么q = k。
2、x不整除k,那么另n=下取整(x/k),则x=p?n
+ q?(n
+ 1)= (p + q)*n + q;那么就可以让q = x%k。那么(p + q)= x/(x/k)。p = x/(x/k) - q;
3、x<k的情况。要单独处理不然会除到0.
代码:
#include <cstdio>
#include <cstring>
int main () {
int T, X, K;
scanf ("%d", &T);
while (T--) {
scanf ("%d%d", &X, &K);
if (X < K) {
printf ("%d %d\n", 0, X);
continue;
}
if (X % K == 0)
printf ("0 %d\n", K);
else {
int q = X % (X / K);
int p = X / (X / K) - q;
printf ("%d %d\n", p, q);
}
}
return 0;
}
UVA10673 - Play with Floor and Ceil(数论)
标签:style http io color ar os sp on 代码
原文地址:http://blog.csdn.net/u012997373/article/details/40950389